Search in sources :

Example 6 with ResolvableType

use of cn.taketoday.core.ResolvableType in project today-infrastructure by TAKETODAY.

the class GenericApplicationListenerAdapterTests method genericListenerStrictTypeAndResolvableType.

// But it works if we specify the type properly
@Test
public void genericListenerStrictTypeAndResolvableType() {
    ResolvableType eventType = ResolvableType.fromClassWithGenerics(GenericTestEvent.class, String.class);
    supportsEventType(true, StringEventListener.class, eventType);
}
Also used : ResolvableType(cn.taketoday.core.ResolvableType) Test(org.junit.jupiter.api.Test)

Example 7 with ResolvableType

use of cn.taketoday.core.ResolvableType in project today-infrastructure by TAKETODAY.

the class GenericApplicationListenerAdapterTests method supportsEventTypeWithSmartApplicationListener.

@Test
public void supportsEventTypeWithSmartApplicationListener() {
    SmartApplicationListener smartListener = mock(SmartApplicationListener.class);
    GenericApplicationListenerAdapter listener = new GenericApplicationListenerAdapter(smartListener);
    ResolvableType type = ResolvableType.fromClass(ApplicationEvent.class);
    listener.supportsEventType(type);
    verify(smartListener, times(1)).supportsEventType(ApplicationEvent.class);
}
Also used : ResolvableType(cn.taketoday.core.ResolvableType) Test(org.junit.jupiter.api.Test)

Example 8 with ResolvableType

use of cn.taketoday.core.ResolvableType in project today-infrastructure by TAKETODAY.

the class GenericApplicationListenerAdapterTests method genericListenerStrictTypeAndResolvableTypeProvider.

// or if the event provides its precise type
@Test
public void genericListenerStrictTypeAndResolvableTypeProvider() {
    ResolvableType eventType = new SmartGenericTestEvent<>(this, "foo").getResolvableType();
    supportsEventType(true, StringEventListener.class, eventType);
}
Also used : ResolvableType(cn.taketoday.core.ResolvableType) Test(org.junit.jupiter.api.Test)

Example 9 with ResolvableType

use of cn.taketoday.core.ResolvableType in project today-infrastructure by TAKETODAY.

the class GenericApplicationListenerAdapterTests method genericListenerStrictTypeEventSubTypeNotMatching.

@Test
public void genericListenerStrictTypeEventSubTypeNotMatching() {
    LongEvent stringEvent = new LongEvent(this, 123L);
    ResolvableType eventType = ResolvableType.fromType(stringEvent.getClass());
    supportsEventType(false, StringEventListener.class, eventType);
}
Also used : ResolvableType(cn.taketoday.core.ResolvableType) Test(org.junit.jupiter.api.Test)

Example 10 with ResolvableType

use of cn.taketoday.core.ResolvableType in project today-infrastructure by TAKETODAY.

the class BeanDefinitionBuilderTests method builderWithResolvableTypeAndInstanceSupplier.

@Test
void builderWithResolvableTypeAndInstanceSupplier() {
    ResolvableType type = ResolvableType.fromClassWithGenerics(Function.class, Integer.class, String.class);
    Function<Integer, String> function = i -> "value " + i;
    RootBeanDefinition rbd = (RootBeanDefinition) BeanDefinitionBuilder.rootBeanDefinition(type, () -> function).getBeanDefinition();
    assertThat(rbd.getResolvableType()).isEqualTo(type);
    assertThat(rbd.getInstanceSupplier()).isNotNull();
    assertThat(rbd.getInstanceSupplier().get()).isInstanceOf(Function.class);
}
Also used : Test(org.junit.jupiter.api.Test) Arrays(java.util.Arrays) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) BeanDefinition(cn.taketoday.beans.factory.config.BeanDefinition) ResolvableType(cn.taketoday.core.ResolvableType) TestBean(cn.taketoday.beans.testfixture.beans.TestBean) Function(java.util.function.Function) 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