Search in sources :

Example 1 with ResolvableType

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);
}
Also used : MockConfigurationPropertySource(cn.taketoday.context.properties.source.MockConfigurationPropertySource) ResolvableType(cn.taketoday.core.ResolvableType) Test(org.junit.jupiter.api.Test)

Example 2 with ResolvableType

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);
    });
}
Also used : ResolvableType(cn.taketoday.core.ResolvableType) Test(org.junit.jupiter.api.Test)

Example 3 with ResolvableType

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();
    });
}
Also used : ResolvableType(cn.taketoday.core.ResolvableType) Test(org.junit.jupiter.api.Test)

Example 4 with ResolvableType

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);
}
Also used : ResolvableType(cn.taketoday.core.ResolvableType)

Example 5 with ResolvableType

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);
}
Also used : ResolvableType(cn.taketoday.core.ResolvableType) Test(org.junit.jupiter.api.Test)

Aggregations

ResolvableType (cn.taketoday.core.ResolvableType)159 Test (org.junit.jupiter.api.Test)106 DataBuffer (cn.taketoday.core.io.buffer.DataBuffer)30 Map (java.util.Map)24 Pojo (cn.taketoday.http.codec.Pojo)20 List (java.util.List)16 MediaType (cn.taketoday.http.MediaType)15 MockConfigurationPropertySource (cn.taketoday.context.properties.source.MockConfigurationPropertySource)14 Flux (reactor.core.publisher.Flux)12 Mono (reactor.core.publisher.Mono)10 Resource (cn.taketoday.core.io.Resource)8 Nullable (cn.taketoday.lang.Nullable)8 ArrayList (java.util.ArrayList)8 IOException (java.io.IOException)7 MultiValueMap (cn.taketoday.core.MultiValueMap)6 ReactiveHttpOutputMessage (cn.taketoday.http.ReactiveHttpOutputMessage)6 ServerSentEvent (cn.taketoday.http.codec.ServerSentEvent)6 MimeType (cn.taketoday.util.MimeType)6 Arrays (java.util.Arrays)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5