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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations