use of org.springframework.core.ResolvableType in project spring-framework by spring-projects.
the class MessageMethodArgumentResolver method getPayloadType.
private Class<?> getPayloadType(MethodParameter parameter) {
Type genericParamType = parameter.getGenericParameterType();
ResolvableType resolvableType = ResolvableType.forType(genericParamType).as(Message.class);
return resolvableType.getGeneric(0).resolve(Object.class);
}
use of org.springframework.core.ResolvableType in project spring-framework by spring-projects.
the class GenericApplicationListenerAdapterTests method supportsEventTypeWithSmartApplicationListener.
@Test
public void supportsEventTypeWithSmartApplicationListener() {
SmartApplicationListener smartListener = mock(SmartApplicationListener.class);
GenericApplicationListenerAdapter listener = new GenericApplicationListenerAdapter(smartListener);
ResolvableType type = ResolvableType.forClass(ApplicationEvent.class);
listener.supportsEventType(type);
verify(smartListener, times(1)).supportsEventType(ApplicationEvent.class);
}
use of org.springframework.core.ResolvableType in project spring-framework by spring-projects.
the class GenericApplicationListenerAdapterTests method genericListenerWildcardTypeTypeErasure.
// Demonstrates we cant inject that event because the listener has a wildcard
@Test
public void genericListenerWildcardTypeTypeErasure() {
GenericTestEvent<String> stringEvent = createGenericTestEvent("test");
ResolvableType eventType = ResolvableType.forType(stringEvent.getClass());
supportsEventType(true, GenericEventListener.class, eventType);
}
use of org.springframework.core.ResolvableType in project spring-framework by spring-projects.
the class GenericApplicationListenerAdapterTests method genericListenerStrictTypeAndResolvableType.
// But it works if we specify the type properly
@Test
public void genericListenerStrictTypeAndResolvableType() {
ResolvableType eventType = ResolvableType.forClassWithGenerics(GenericTestEvent.class, String.class);
supportsEventType(true, StringEventListener.class, eventType);
}
use of org.springframework.core.ResolvableType in project spring-framework by spring-projects.
the class GenericApplicationListenerAdapterTests method genericListenerStrictTypeNotMatchTypeErasure.
@Test
public void genericListenerStrictTypeNotMatchTypeErasure() {
GenericTestEvent<Long> longEvent = createGenericTestEvent(123L);
ResolvableType eventType = ResolvableType.forType(longEvent.getClass());
supportsEventType(false, StringEventListener.class, eventType);
}
Aggregations