SimpleApplicationEventMulticaster just swallows event downcast exceptions
Issue: SPR-14846
This commit is contained in:
@@ -379,6 +379,50 @@ public class ApplicationContextEventTests extends AbstractApplicationEventListen
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void anonymousClassAsListener() {
|
||||
final Set<MyEvent> seenEvents = new HashSet<>();
|
||||
StaticApplicationContext context = new StaticApplicationContext();
|
||||
context.addApplicationListener(new ApplicationListener<MyEvent>() {
|
||||
@Override
|
||||
public void onApplicationEvent(MyEvent event) {
|
||||
seenEvents.add(event);
|
||||
}
|
||||
});
|
||||
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
|
||||
public void lambdaAsListener() {
|
||||
final Set<MyEvent> seenEvents = new HashSet<>();
|
||||
StaticApplicationContext context = new StaticApplicationContext();
|
||||
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
|
||||
public void beanPostProcessorPublishesEvents() {
|
||||
GenericApplicationContext context = new GenericApplicationContext();
|
||||
|
||||
Reference in New Issue
Block a user