1
1
/*
2
- * Copyright 2002-2021 the original author or authors.
2
+ * Copyright 2002-2023 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -164,12 +164,12 @@ void contextEventsAreReceived() {
164
164
ContextEventListener listener = this .context .getBean (ContextEventListener .class );
165
165
166
166
List <Object > events = this .eventCollector .getEvents (listener );
167
- assertThat (events . size ()) .as ("Wrong number of initial context events" ).isEqualTo (1 );
167
+ assertThat (events ) .as ("Wrong number of initial context events" ).hasSize (1 );
168
168
assertThat (events .get (0 ).getClass ()).isEqualTo (ContextRefreshedEvent .class );
169
169
170
170
this .context .stop ();
171
171
List <Object > eventsAfterStop = this .eventCollector .getEvents (listener );
172
- assertThat (eventsAfterStop . size ()) .as ("Wrong number of context events on shutdown" ).isEqualTo (2 );
172
+ assertThat (eventsAfterStop ) .as ("Wrong number of context events on shutdown" ).hasSize (2 );
173
173
assertThat (eventsAfterStop .get (1 ).getClass ()).isEqualTo (ContextStoppedEvent .class );
174
174
this .eventCollector .assertTotalEventsCount (2 );
175
175
}
@@ -334,7 +334,7 @@ void eventListenerWorksWithSimpleInterfaceProxy() {
334
334
load (ScopedProxyTestBean .class );
335
335
336
336
SimpleService proxy = this .context .getBean (SimpleService .class );
337
- assertThat (proxy instanceof Advised ).as ("bean should be a proxy" ).isTrue ( );
337
+ assertThat (proxy ).as ("bean should be a proxy" ).isInstanceOf ( Advised . class );
338
338
this .eventCollector .assertNoEventReceived (proxy .getId ());
339
339
340
340
this .context .publishEvent (new ContextRefreshedEvent (this .context ));
@@ -351,7 +351,7 @@ void eventListenerWorksWithAnnotatedInterfaceProxy() {
351
351
load (AnnotatedProxyTestBean .class );
352
352
353
353
AnnotatedSimpleService proxy = this .context .getBean (AnnotatedSimpleService .class );
354
- assertThat (proxy instanceof Advised ).as ("bean should be a proxy" ).isTrue ( );
354
+ assertThat (proxy ).as ("bean should be a proxy" ).isInstanceOf ( Advised . class );
355
355
this .eventCollector .assertNoEventReceived (proxy .getId ());
356
356
357
357
this .context .publishEvent (new ContextRefreshedEvent (this .context ));
@@ -517,7 +517,6 @@ void replyWithPayload() {
517
517
ReplyEventListener replyEventListener = this .context .getBean (ReplyEventListener .class );
518
518
TestEventListener listener = this .context .getBean (TestEventListener .class );
519
519
520
-
521
520
this .eventCollector .assertNoEventReceived (listener );
522
521
this .eventCollector .assertNoEventReceived (replyEventListener );
523
522
this .context .publishEvent (event );
@@ -634,6 +633,17 @@ void orderedListeners() {
634
633
assertThat (listener .order ).contains ("first" , "second" , "third" );
635
634
}
636
635
636
+ @ Test
637
+ void publicSubclassWithInheritedEventListener () {
638
+ load (PublicSubclassWithInheritedEventListener .class );
639
+ TestEventListener listener = this .context .getBean (PublicSubclassWithInheritedEventListener .class );
640
+
641
+ this .eventCollector .assertNoEventReceived (listener );
642
+ this .context .publishEvent ("test" );
643
+ this .eventCollector .assertEvent (listener , "test" );
644
+ this .eventCollector .assertTotalEventsCount (1 );
645
+ }
646
+
637
647
@ Test @ Disabled // SPR-15122
638
648
void listenersReceiveEarlyEvents () {
639
649
load (EventOnPostConstruct .class , OrderedTestListener .class );
@@ -646,7 +656,7 @@ void listenersReceiveEarlyEvents() {
646
656
void missingListenerBeanIgnored () {
647
657
load (MissingEventListener .class );
648
658
context .getBean (UseMissingEventListener .class );
649
- context .getBean ( ApplicationEventMulticaster . class ). multicastEvent (new TestEvent (this ));
659
+ context .publishEvent (new TestEvent (this ));
650
660
}
651
661
652
662
@@ -753,7 +763,6 @@ static class ContextEventListener extends AbstractTestEventListener {
753
763
public void handleContextEvent (ApplicationContextEvent event ) {
754
764
collectEvent (event );
755
765
}
756
-
757
766
}
758
767
759
768
@@ -980,7 +989,6 @@ public void handleString(GenericEventPojo<String> value) {
980
989
}
981
990
982
991
983
-
984
992
@ EventListener
985
993
@ Retention (RetentionPolicy .RUNTIME )
986
994
public @interface ConditionalEvent {
@@ -1032,7 +1040,7 @@ public void handleRatio(Double ratio) {
1032
1040
}
1033
1041
1034
1042
1035
- @ Configuration
1043
+ @ Component
1036
1044
static class OrderedTestListener extends TestEventListener {
1037
1045
1038
1046
public final List <String > order = new ArrayList <>();
@@ -1056,6 +1064,11 @@ public void handleSecond(String payload) {
1056
1064
}
1057
1065
1058
1066
1067
+ @ Component
1068
+ public static class PublicSubclassWithInheritedEventListener extends TestEventListener {
1069
+ }
1070
+
1071
+
1059
1072
static class EventOnPostConstruct {
1060
1073
1061
1074
@ Autowired
0 commit comments