use of cn.taketoday.context.ApplicationEvent in project today-infrastructure by TAKETODAY.
the class ApplicationContextEventTests method simpleApplicationEventMulticasterWithException.
@Test
public void simpleApplicationEventMulticasterWithException() {
@SuppressWarnings("unchecked") ApplicationListener<ApplicationEvent> listener = mock(ApplicationListener.class);
ApplicationEvent evt = new ContextClosedEvent(new StaticApplicationContext());
SimpleApplicationEventMulticaster smc = new SimpleApplicationEventMulticaster();
smc.addApplicationListener(listener);
RuntimeException thrown = new RuntimeException();
willThrow(thrown).given(listener).onApplicationEvent(evt);
assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> smc.multicastEvent(evt)).satisfies(ex -> assertThat(ex).isSameAs(thrown));
}
use of cn.taketoday.context.ApplicationEvent in project today-infrastructure by TAKETODAY.
the class ApplicationContextEventTests method simpleApplicationEventMulticasterWithErrorHandler.
@Test
public void simpleApplicationEventMulticasterWithErrorHandler() {
@SuppressWarnings("unchecked") ApplicationListener<ApplicationEvent> listener = mock(ApplicationListener.class);
ApplicationEvent evt = new ContextClosedEvent(new StaticApplicationContext());
SimpleApplicationEventMulticaster smc = new SimpleApplicationEventMulticaster();
smc.setErrorHandler(TaskUtils.LOG_AND_SUPPRESS_ERROR_HANDLER);
smc.addApplicationListener(listener);
willThrow(new RuntimeException()).given(listener).onApplicationEvent(evt);
smc.multicastEvent(evt);
}
use of cn.taketoday.context.ApplicationEvent in project today-infrastructure by TAKETODAY.
the class ApplicationContextEventTests method lambdaAsListenerWithJava9StyleClassCastMessage.
@Test
public void lambdaAsListenerWithJava9StyleClassCastMessage() {
StaticApplicationContext context = new StaticApplicationContext();
ApplicationListener<ApplicationEvent> listener = event -> {
throw new ClassCastException("spring.context/" + event.getClass().getName());
};
context.addApplicationListener(listener);
context.refresh();
context.publishEvent(new MyEvent(context));
context.close();
}
Aggregations