use of cn.taketoday.core.ResolvableType in project today-infrastructure by TAKETODAY.
the class ArrayBinderTests method bindToArrayWhenNestedShouldReturnPopulatedArray.
@Test
void bindToArrayWhenNestedShouldReturnPopulatedArray() {
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
source.put("foo[0][0]", "1");
source.put("foo[0][1]", "2");
source.put("foo[1][0]", "3");
source.put("foo[1][1]", "4");
this.sources.add(source);
ResolvableType type = ResolvableType.fromArrayComponent(INTEGER_ARRAY.getType());
Bindable<Integer[][]> target = Bindable.of(type);
Integer[][] result = this.binder.bind("foo", target).get();
assertThat(result).hasDimensions(2, 2);
assertThat(result[0]).containsExactly(1, 2);
assertThat(result[1]).containsExactly(3, 4);
}
use of cn.taketoday.core.ResolvableType in project today-infrastructure by TAKETODAY.
the class ConfigurationPropertiesBeanTests method getWhenHasFactoryMethodWithoutAnnotationBindsUsingMethodType.
@Test
void getWhenHasFactoryMethodWithoutAnnotationBindsUsingMethodType() throws Throwable {
get(AnnotatedGenericBeanConfiguration.class, "annotatedGenericBean", (propertiesBean) -> {
assertThat(propertiesBean.getType()).isEqualTo(AnnotatedGenericBean.class);
assertThat(propertiesBean.getBindMethod()).isEqualTo(BindMethod.JAVA_BEAN);
ResolvableType type = propertiesBean.asBindTarget().getType();
assertThat(type.resolve()).isEqualTo(AnnotatedGenericBean.class);
assertThat(type.resolveGeneric(0)).isEqualTo(String.class);
});
}
use of cn.taketoday.core.ResolvableType in project today-infrastructure by TAKETODAY.
the class ConfigurationPropertiesBeanTests method getWhenHasNoFactoryMethodBindsUsingObjectType.
@Test
void getWhenHasNoFactoryMethodBindsUsingObjectType() throws Throwable {
get(AnnotatedGenericComponent.class, "annotatedGenericComponent", (propertiesBean) -> {
assertThat(propertiesBean.getType()).isEqualTo(AnnotatedGenericComponent.class);
assertThat(propertiesBean.getBindMethod()).isEqualTo(BindMethod.JAVA_BEAN);
ResolvableType type = propertiesBean.asBindTarget().getType();
assertThat(type.resolve()).isEqualTo(AnnotatedGenericComponent.class);
assertThat(type.getGeneric(0).resolve()).isNull();
});
}
use of cn.taketoday.core.ResolvableType in project today-infrastructure by TAKETODAY.
the class BeanUtils method isAssignable.
private static boolean isAssignable(Method writeMethod, Method readMethod) {
ResolvableType sourceResolvableType = ResolvableType.forReturnType(readMethod);
ResolvableType targetResolvableType = ResolvableType.forParameter(writeMethod, 0);
// Ignore generic types in assignable check if either ResolvableType has unresolvable generics.
return (sourceResolvableType.hasUnresolvableGenerics() || targetResolvableType.hasUnresolvableGenerics()) ? ClassUtils.isAssignable(writeMethod.getParameterTypes()[0], readMethod.getReturnType()) : targetResolvableType.isAssignableFrom(sourceResolvableType);
}
use of cn.taketoday.core.ResolvableType in project today-infrastructure by TAKETODAY.
the class GenericApplicationListenerAdapterTests method genericListenerStrictTypeTypeErasure.
// Demonstrates we can't inject that event because the generic type is lost
@Test
public void genericListenerStrictTypeTypeErasure() {
GenericTestEvent<String> stringEvent = createGenericTestEvent("test");
ResolvableType eventType = ResolvableType.fromType(stringEvent.getClass());
supportsEventType(false, StringEventListener.class, eventType);
}
Aggregations