Polishing
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -111,7 +111,7 @@ class AnnotationDrivenEventListenerTests {
|
||||
this.eventCollector.assertTotalEventsCount(1);
|
||||
|
||||
context.getBean(ApplicationEventMulticaster.class).removeApplicationListeners(l ->
|
||||
l instanceof SmartApplicationListener && ((SmartApplicationListener) l).getListenerId().contains("TestEvent"));
|
||||
l instanceof SmartApplicationListener sal && sal.getListenerId().contains("TestEvent"));
|
||||
this.eventCollector.clear();
|
||||
this.context.publishEvent(event);
|
||||
this.eventCollector.assertNoEventReceived(listener);
|
||||
@@ -132,7 +132,7 @@ class AnnotationDrivenEventListenerTests {
|
||||
this.eventCollector.assertTotalEventsCount(1);
|
||||
|
||||
context.getBean(ApplicationEventMulticaster.class).removeApplicationListeners(l ->
|
||||
l instanceof SmartApplicationListener && ((SmartApplicationListener) l).getListenerId().contains("TestEvent"));
|
||||
l instanceof SmartApplicationListener sal && sal.getListenerId().contains("TestEvent"));
|
||||
this.eventCollector.clear();
|
||||
this.context.publishEvent(event);
|
||||
this.eventCollector.assertNoEventReceived(listener);
|
||||
@@ -150,7 +150,7 @@ class AnnotationDrivenEventListenerTests {
|
||||
this.eventCollector.assertTotalEventsCount(1);
|
||||
|
||||
context.getBean(ApplicationEventMulticaster.class).removeApplicationListeners(l ->
|
||||
l instanceof SmartApplicationListener && ((SmartApplicationListener) l).getListenerId().equals("foo"));
|
||||
l instanceof SmartApplicationListener sal && sal.getListenerId().equals("foo"));
|
||||
this.eventCollector.clear();
|
||||
this.context.publishEvent(event);
|
||||
this.eventCollector.assertNoEventReceived(bean);
|
||||
|
||||
@@ -39,7 +39,6 @@ import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.context.ApplicationEventPublisherAware;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.context.PayloadApplicationEvent;
|
||||
import org.springframework.context.support.AbstractApplicationContext;
|
||||
import org.springframework.context.support.GenericApplicationContext;
|
||||
import org.springframework.context.support.StaticApplicationContext;
|
||||
import org.springframework.context.support.StaticMessageSource;
|
||||
@@ -59,6 +58,7 @@ import static org.mockito.BDDMockito.willThrow;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.springframework.context.support.AbstractApplicationContext.APPLICATION_EVENT_MULTICASTER_BEAN_NAME;
|
||||
|
||||
/**
|
||||
* Unit and integration tests for the ApplicationContext event support.
|
||||
@@ -163,7 +163,7 @@ public class ApplicationContextEventTests extends AbstractApplicationEventListen
|
||||
willThrow(thrown).given(listener).onApplicationEvent(evt);
|
||||
assertThatRuntimeException()
|
||||
.isThrownBy(() -> smc.multicastEvent(evt))
|
||||
.satisfies(ex -> assertThat(ex).isSameAs(thrown));
|
||||
.isSameAs(thrown);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -282,20 +282,14 @@ public class ApplicationContextEventTests extends AbstractApplicationEventListen
|
||||
context.publishEvent(event3);
|
||||
MyOtherEvent event4 = new MyOtherEvent(context);
|
||||
context.publishEvent(event4);
|
||||
assertThat(listener1.seenEvents.contains(event1)).isTrue();
|
||||
assertThat(listener1.seenEvents.contains(event2)).isTrue();
|
||||
assertThat(listener1.seenEvents.contains(event3)).isTrue();
|
||||
assertThat(listener1.seenEvents.contains(event4)).isTrue();
|
||||
assertThat(listener1.seenEvents).contains(event1, event2, event3, event4);
|
||||
|
||||
listener1.seenEvents.clear();
|
||||
context.publishEvent(event1);
|
||||
context.publishEvent(event2);
|
||||
context.publishEvent(event3);
|
||||
context.publishEvent(event4);
|
||||
assertThat(listener1.seenEvents.contains(event1)).isTrue();
|
||||
assertThat(listener1.seenEvents.contains(event2)).isTrue();
|
||||
assertThat(listener1.seenEvents.contains(event3)).isTrue();
|
||||
assertThat(listener1.seenEvents.contains(event4)).isTrue();
|
||||
assertThat(listener1.seenEvents).contains(event1, event2, event3, event4);
|
||||
|
||||
AbstractApplicationEventMulticaster multicaster = context.getBean(AbstractApplicationEventMulticaster.class);
|
||||
assertThat(multicaster.retrieverCache).hasSize(2);
|
||||
@@ -314,10 +308,7 @@ public class ApplicationContextEventTests extends AbstractApplicationEventListen
|
||||
context.publishEvent("event2");
|
||||
context.publishEvent("event3");
|
||||
context.publishEvent("event4");
|
||||
assertThat(listener.seenPayloads.contains("event1")).isTrue();
|
||||
assertThat(listener.seenPayloads.contains("event2")).isTrue();
|
||||
assertThat(listener.seenPayloads.contains("event3")).isTrue();
|
||||
assertThat(listener.seenPayloads.contains("event4")).isTrue();
|
||||
assertThat(listener.seenPayloads).contains("event1", "event2", "event3", "event4");
|
||||
|
||||
AbstractApplicationEventMulticaster multicaster = context.getBean(AbstractApplicationEventMulticaster.class);
|
||||
assertThat(multicaster.retrieverCache).hasSize(2);
|
||||
@@ -340,15 +331,13 @@ public class ApplicationContextEventTests extends AbstractApplicationEventListen
|
||||
MyOrderedListener1 listener1 = context.getBean("listener1", MyOrderedListener1.class);
|
||||
MyEvent event1 = new MyEvent(context);
|
||||
context.publishEvent(event1);
|
||||
assertThat(listener1.seenEvents.contains(event1)).isTrue();
|
||||
assertThat(listener1.seenEvents).contains(event1);
|
||||
|
||||
SimpleApplicationEventMulticaster multicaster = context.getBean(
|
||||
AbstractApplicationContext.APPLICATION_EVENT_MULTICASTER_BEAN_NAME,
|
||||
SimpleApplicationEventMulticaster.class);
|
||||
assertThat(multicaster.getApplicationListeners().isEmpty()).isFalse();
|
||||
SimpleApplicationEventMulticaster multicaster = context.getBean(SimpleApplicationEventMulticaster.class);
|
||||
assertThat(multicaster.getApplicationListeners()).isNotEmpty();
|
||||
|
||||
context.close();
|
||||
assertThat(multicaster.getApplicationListeners().isEmpty()).isTrue();
|
||||
assertThat(multicaster.getApplicationListeners()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -367,20 +356,14 @@ public class ApplicationContextEventTests extends AbstractApplicationEventListen
|
||||
context.publishEvent(event3);
|
||||
MyOtherEvent event4 = new MyOtherEvent(context);
|
||||
context.publishEvent(event4);
|
||||
assertThat(MyNonSingletonListener.seenEvents.contains(event1)).isTrue();
|
||||
assertThat(MyNonSingletonListener.seenEvents.contains(event2)).isTrue();
|
||||
assertThat(MyNonSingletonListener.seenEvents.contains(event3)).isTrue();
|
||||
assertThat(MyNonSingletonListener.seenEvents.contains(event4)).isTrue();
|
||||
assertThat(MyNonSingletonListener.seenEvents).contains(event1, event2, event3, event4);
|
||||
MyNonSingletonListener.seenEvents.clear();
|
||||
|
||||
context.publishEvent(event1);
|
||||
context.publishEvent(event2);
|
||||
context.publishEvent(event3);
|
||||
context.publishEvent(event4);
|
||||
assertThat(MyNonSingletonListener.seenEvents.contains(event1)).isTrue();
|
||||
assertThat(MyNonSingletonListener.seenEvents.contains(event2)).isTrue();
|
||||
assertThat(MyNonSingletonListener.seenEvents.contains(event3)).isTrue();
|
||||
assertThat(MyNonSingletonListener.seenEvents.contains(event4)).isTrue();
|
||||
assertThat(MyNonSingletonListener.seenEvents).contains(event1, event2, event3, event4);
|
||||
MyNonSingletonListener.seenEvents.clear();
|
||||
|
||||
AbstractApplicationEventMulticaster multicaster = context.getBean(AbstractApplicationEventMulticaster.class);
|
||||
@@ -433,9 +416,7 @@ public class ApplicationContextEventTests extends AbstractApplicationEventListen
|
||||
context.publishEvent(new MyOtherEvent(context));
|
||||
MyEvent event2 = new MyEvent(context);
|
||||
context.publishEvent(event2);
|
||||
assertThat(seenEvents.size()).isSameAs(2);
|
||||
assertThat(seenEvents.contains(event1)).isTrue();
|
||||
assertThat(seenEvents.contains(event2)).isTrue();
|
||||
assertThat(seenEvents).contains(event1, event2);
|
||||
|
||||
context.close();
|
||||
}
|
||||
@@ -453,9 +434,7 @@ public class ApplicationContextEventTests extends AbstractApplicationEventListen
|
||||
context.publishEvent(new MyOtherEvent(context));
|
||||
MyEvent event2 = new MyEvent(context);
|
||||
context.publishEvent(event2);
|
||||
assertThat(seenEvents.size()).isSameAs(2);
|
||||
assertThat(seenEvents.contains(event1)).isTrue();
|
||||
assertThat(seenEvents.contains(event2)).isTrue();
|
||||
assertThat(seenEvents).contains(event1, event2);
|
||||
|
||||
context.close();
|
||||
}
|
||||
@@ -466,8 +445,7 @@ public class ApplicationContextEventTests extends AbstractApplicationEventListen
|
||||
StaticApplicationContext context = new StaticApplicationContext();
|
||||
SimpleApplicationEventMulticaster multicaster = new SimpleApplicationEventMulticaster();
|
||||
multicaster.setErrorHandler(ReflectionUtils::rethrowRuntimeException);
|
||||
context.getBeanFactory().registerSingleton(
|
||||
StaticApplicationContext.APPLICATION_EVENT_MULTICASTER_BEAN_NAME, multicaster);
|
||||
context.getBeanFactory().registerSingleton(APPLICATION_EVENT_MULTICASTER_BEAN_NAME, multicaster);
|
||||
ApplicationListener<MyEvent> listener = seenEvents::add;
|
||||
context.addApplicationListener(listener);
|
||||
context.refresh();
|
||||
@@ -477,9 +455,7 @@ public class ApplicationContextEventTests extends AbstractApplicationEventListen
|
||||
context.publishEvent(new MyOtherEvent(context));
|
||||
MyEvent event2 = new MyEvent(context);
|
||||
context.publishEvent(event2);
|
||||
assertThat(seenEvents.size()).isSameAs(2);
|
||||
assertThat(seenEvents.contains(event1)).isTrue();
|
||||
assertThat(seenEvents.contains(event2)).isTrue();
|
||||
assertThat(seenEvents).containsExactlyInAnyOrder(event1, event2);
|
||||
|
||||
context.close();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -56,7 +56,7 @@ public class StaticApplicationContextMulticasterTests extends AbstractApplicatio
|
||||
parent.registerPrototype("rod", TestBean.class, new MutablePropertyValues(m));
|
||||
m.put("name", "Albert");
|
||||
parent.registerPrototype("father", TestBean.class, new MutablePropertyValues(m));
|
||||
parent.registerSingleton(StaticApplicationContext.APPLICATION_EVENT_MULTICASTER_BEAN_NAME,
|
||||
parent.registerSingleton(AbstractApplicationContext.APPLICATION_EVENT_MULTICASTER_BEAN_NAME,
|
||||
TestApplicationEventMulticaster.class, null);
|
||||
parent.refresh();
|
||||
parent.addApplicationListener(parentListener) ;
|
||||
|
||||
Reference in New Issue
Block a user