Search in sources :

Example 1 with PayloadApplicationEvent

use of org.springframework.context.PayloadApplicationEvent in project spring-framework by spring-projects.

the class ApplicationListenerMethodAdapterTests method invokeListenerWithPayload.

@Test
public void invokeListenerWithPayload() {
    Method method = ReflectionUtils.findMethod(SampleEvents.class, "handleString", String.class);
    PayloadApplicationEvent<String> event = new PayloadApplicationEvent<>(this, "test");
    invokeListener(method, event);
    verify(this.sampleEvents, times(1)).handleString("test");
}
Also used : PayloadApplicationEvent(org.springframework.context.PayloadApplicationEvent) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 2 with PayloadApplicationEvent

use of org.springframework.context.PayloadApplicationEvent in project spring-framework by spring-projects.

the class ApplicationListenerMethodAdapterTests method invokeListenerWithAnnotationValueAndParameter.

@Test
public void invokeListenerWithAnnotationValueAndParameter() {
    Method method = ReflectionUtils.findMethod(SampleEvents.class, "handleStringAnnotationValueAndParameter", String.class);
    PayloadApplicationEvent<String> event = new PayloadApplicationEvent<>(this, "test");
    invokeListener(method, event);
    verify(this.sampleEvents, times(1)).handleStringAnnotationValueAndParameter("test");
}
Also used : PayloadApplicationEvent(org.springframework.context.PayloadApplicationEvent) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 3 with PayloadApplicationEvent

use of org.springframework.context.PayloadApplicationEvent in project spring-framework by spring-projects.

the class ApplicationListenerMethodAdapterTests method invokeListenerWithAnnotationValue.

@Test
public void invokeListenerWithAnnotationValue() {
    Method method = ReflectionUtils.findMethod(SampleEvents.class, "handleStringAnnotationClasses");
    PayloadApplicationEvent<String> event = new PayloadApplicationEvent<>(this, "test");
    invokeListener(method, event);
    verify(this.sampleEvents, times(1)).handleStringAnnotationClasses();
}
Also used : PayloadApplicationEvent(org.springframework.context.PayloadApplicationEvent) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 4 with PayloadApplicationEvent

use of org.springframework.context.PayloadApplicationEvent in project spring-framework by spring-projects.

the class ApplicationListenerMethodAdapterTests method invokeListenerWithPayloadWrongType.

@Test
public void invokeListenerWithPayloadWrongType() {
    Method method = ReflectionUtils.findMethod(SampleEvents.class, "handleString", String.class);
    PayloadApplicationEvent<Long> event = new PayloadApplicationEvent<>(this, 123L);
    invokeListener(method, event);
    verify(this.sampleEvents, never()).handleString(anyString());
}
Also used : PayloadApplicationEvent(org.springframework.context.PayloadApplicationEvent) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 5 with PayloadApplicationEvent

use of org.springframework.context.PayloadApplicationEvent in project spring-framework by spring-projects.

the class ApplicationListenerMethodAdapterTests method invokeListenerWithSeveralTypes.

@Test
public void invokeListenerWithSeveralTypes() {
    Method method = ReflectionUtils.findMethod(SampleEvents.class, "handleStringOrInteger");
    PayloadApplicationEvent<String> event = new PayloadApplicationEvent<>(this, "test");
    invokeListener(method, event);
    verify(this.sampleEvents, times(1)).handleStringOrInteger();
    PayloadApplicationEvent<Integer> event2 = new PayloadApplicationEvent<>(this, 123);
    invokeListener(method, event2);
    verify(this.sampleEvents, times(2)).handleStringOrInteger();
    PayloadApplicationEvent<Double> event3 = new PayloadApplicationEvent<>(this, 23.2);
    invokeListener(method, event3);
    verify(this.sampleEvents, times(2)).handleStringOrInteger();
}
Also used : PayloadApplicationEvent(org.springframework.context.PayloadApplicationEvent) Method(java.lang.reflect.Method) Test(org.junit.Test)

Aggregations

PayloadApplicationEvent (org.springframework.context.PayloadApplicationEvent)7 Method (java.lang.reflect.Method)5 Test (org.junit.Test)5 ApplicationEvent (org.springframework.context.ApplicationEvent)1 ResolvableType (org.springframework.core.ResolvableType)1