|
|
|
@ -46,6 +46,7 @@ import org.springframework.core.ResolvableType; |
|
|
|
import org.springframework.core.annotation.Order; |
|
|
|
import org.springframework.core.annotation.Order; |
|
|
|
import org.springframework.scheduling.support.TaskUtils; |
|
|
|
import org.springframework.scheduling.support.TaskUtils; |
|
|
|
import org.springframework.tests.sample.beans.TestBean; |
|
|
|
import org.springframework.tests.sample.beans.TestBean; |
|
|
|
|
|
|
|
import org.springframework.util.ReflectionUtils; |
|
|
|
|
|
|
|
|
|
|
|
import static org.junit.Assert.*; |
|
|
|
import static org.junit.Assert.*; |
|
|
|
import static org.mockito.BDDMockito.*; |
|
|
|
import static org.mockito.BDDMockito.*; |
|
|
|
@ -447,6 +448,30 @@ public class ApplicationContextEventTests extends AbstractApplicationEventListen |
|
|
|
context.close(); |
|
|
|
context.close(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void lambdaAsListenerWithErrorHandler() { |
|
|
|
|
|
|
|
final Set<MyEvent> seenEvents = new HashSet<>(); |
|
|
|
|
|
|
|
StaticApplicationContext context = new StaticApplicationContext(); |
|
|
|
|
|
|
|
SimpleApplicationEventMulticaster multicaster = new SimpleApplicationEventMulticaster(); |
|
|
|
|
|
|
|
multicaster.setErrorHandler(ReflectionUtils::rethrowRuntimeException); |
|
|
|
|
|
|
|
context.getBeanFactory().registerSingleton( |
|
|
|
|
|
|
|
StaticApplicationContext.APPLICATION_EVENT_MULTICASTER_BEAN_NAME, multicaster); |
|
|
|
|
|
|
|
ApplicationListener<MyEvent> listener = seenEvents::add; |
|
|
|
|
|
|
|
context.addApplicationListener(listener); |
|
|
|
|
|
|
|
context.refresh(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MyEvent event1 = new MyEvent(context); |
|
|
|
|
|
|
|
context.publishEvent(event1); |
|
|
|
|
|
|
|
context.publishEvent(new MyOtherEvent(context)); |
|
|
|
|
|
|
|
MyEvent event2 = new MyEvent(context); |
|
|
|
|
|
|
|
context.publishEvent(event2); |
|
|
|
|
|
|
|
assertSame(2, seenEvents.size()); |
|
|
|
|
|
|
|
assertTrue(seenEvents.contains(event1)); |
|
|
|
|
|
|
|
assertTrue(seenEvents.contains(event2)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context.close(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void beanPostProcessorPublishesEvents() { |
|
|
|
public void beanPostProcessorPublishesEvents() { |
|
|
|
GenericApplicationContext context = new GenericApplicationContext(); |
|
|
|
GenericApplicationContext context = new GenericApplicationContext(); |
|
|
|
|