Skip to content

Commit

Permalink
write a line into test.file
Browse files Browse the repository at this point in the history
  • Loading branch information
huifer committed Oct 14, 2023
1 parent c6a49f2 commit b0524ba
Show file tree
Hide file tree
Showing 2 changed files with 182 additions and 0 deletions.
85 changes: 85 additions & 0 deletions docs/spring/cs2ddc02ac-6a3d-11ee-8880-acde48001122.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/**
* Copyright 2009-2019 the original author or authors.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.ibatis.type;

import org.junit.jupiter.api.Test;

import java.time.LocalTime;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.mockito.Mockito.*;

class LocalTimeTypeHandlerTest extends BaseTypeHandlerTest {

private static final TypeHandler<LocalTime> TYPE_HANDLER = new LocalTimeTypeHandler();
private static final LocalTime LOCAL_TIME = LocalTime.now();

@Override
@Test
public void shouldSetParameter() throws Exception {
TYPE_HANDLER.setParameter(ps, 1, LOCAL_TIME, null);
verify(ps).setObject(1, LOCAL_TIME);
}

@Override
@Test
public void shouldGetResultFromResultSetByName() throws Exception {
when(rs.getObject("column", LocalTime.class)).thenReturn(LOCAL_TIME);
assertEquals(LOCAL_TIME, TYPE_HANDLER.getResult(rs, "column"));
verify(rs, never()).wasNull();
}

@Override
@Test
public void shouldGetResultNullFromResultSetByName() throws Exception {
when(rs.getObject("column", LocalTime.class)).thenReturn(null);
assertNull(TYPE_HANDLER.getResult(rs, "column"));
verify(rs, never()).wasNull();
}

@Override
@Test
public void shouldGetResultFromResultSetByPosition() throws Exception {
when(rs.getObject(1, LocalTime.class)).thenReturn(LOCAL_TIME);
assertEquals(LOCAL_TIME, TYPE_HANDLER.getResult(rs, 1));
verify(rs, never()).wasNull();
}

@Override
@Test
public void shouldGetResultNullFromResultSetByPosition() throws Exception {
when(rs.getObject(1, LocalTime.class)).thenReturn(null);
assertNull(TYPE_HANDLER.getResult(rs, 1));
verify(rs, never()).wasNull();
}

@Override
@Test
public void shouldGetResultFromCallableStatement() throws Exception {
when(cs.getObject(1, LocalTime.class)).thenReturn(LOCAL_TIME);
assertEquals(LOCAL_TIME, TYPE_HANDLER.getResult(cs, 1));
verify(cs, never()).wasNull();
}

@Override
@Test
public void shouldGetResultNullFromCallableStatement() throws Exception {
when(cs.getObject(1, LocalTime.class)).thenReturn(null);
assertNull(TYPE_HANDLER.getResult(cs, 1));
verify(cs, never()).wasNull();
}
}
97 changes: 97 additions & 0 deletions docs/spring/cs2e1aae58-6a3d-11ee-8880-acde48001122.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package com.huifer.feign.annotation;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;

import java.lang.reflect.Proxy;
import java.util.Arrays;
import java.util.Map;

import static org.springframework.core.annotation.AnnotationUtils.findAnnotation;

/**
* <p>Title : FeignClientsRegistart </p>
* <p>Description : </p>
*
* @author huifer
* @date 2019-05-30
*/
public class FeignClientsRegistart implements ImportBeanDefinitionRegistrar, BeanFactoryAware {

private BeanFactory beanfactory;

@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata,
BeanDefinitionRegistry registry) {

ClassLoader classLoader = importingClassMetadata.getClass().getClassLoader();

Map<String, Object> attributes = importingClassMetadata
.getAnnotationAttributes(EnableRestClient.class.getName());

// 接口对象类
Class<?>[] clientClasses = (Class<?>[]) attributes.get("clients");
// 过滤接口 RestClient
Arrays.stream(clientClasses).filter(Class::isInterface)
.filter(interfaceClas ->
findAnnotation(interfaceClas, RestClient.class) != null)
.forEach(
restClientClass -> {
// 获取注解信息
RestClient annotation = findAnnotation(restClientClass,
RestClient.class);
String serverName = annotation.name();
Object proxyInstance = Proxy
.newProxyInstance(classLoader, new Class[]{restClientClass},
new ReuqestMappingHandler(serverName, beanfactory));

BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder.genericBeanDefinition(RestClientClassFactorBean.class);

beanDefinitionBuilder.addConstructorArgValue(proxyInstance);
beanDefinitionBuilder.addConstructorArgValue(restClientClass);

BeanDefinition beanDefinition = beanDefinitionBuilder
.getBeanDefinition();
String beanName = "RestClient" + serverName;
registry.registerBeanDefinition(beanName, beanDefinition);
});


}

@Override
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
this.beanfactory = beanFactory;
}

private static class RestClientClassFactorBean implements FactoryBean {

private final Object proxy;
private final Class<?> restClientClass;


public RestClientClassFactorBean(Object proxy, Class<?> restClientClass) {
this.proxy = proxy;
this.restClientClass = restClientClass;
}

@Override
public Object getObject() throws Exception {
return proxy;
}

@Override
public Class<?> getObjectType() {
return restClientClass;
}
}


}

0 comments on commit b0524ba

Please sign in to comment.