@@ -379,6 +379,50 @@ public void innerBeanAsListener() {
379
379
context .close ();
380
380
}
381
381
382
+ @ Test
383
+ public void anonymousClassAsListener () {
384
+ final Set <MyEvent > seenEvents = new HashSet <>();
385
+ StaticApplicationContext context = new StaticApplicationContext ();
386
+ context .addApplicationListener (new ApplicationListener <MyEvent >() {
387
+ @ Override
388
+ public void onApplicationEvent (MyEvent event ) {
389
+ seenEvents .add (event );
390
+ }
391
+ });
392
+ context .refresh ();
393
+
394
+ MyEvent event1 = new MyEvent (context );
395
+ context .publishEvent (event1 );
396
+ context .publishEvent (new MyOtherEvent (context ));
397
+ MyEvent event2 = new MyEvent (context );
398
+ context .publishEvent (event2 );
399
+ assertSame (2 , seenEvents .size ());
400
+ assertTrue (seenEvents .contains (event1 ));
401
+ assertTrue (seenEvents .contains (event2 ));
402
+
403
+ context .close ();
404
+ }
405
+
406
+ @ Test
407
+ public void lambdaAsListener () {
408
+ final Set <MyEvent > seenEvents = new HashSet <>();
409
+ StaticApplicationContext context = new StaticApplicationContext ();
410
+ ApplicationListener <MyEvent > listener = seenEvents ::add ;
411
+ context .addApplicationListener (listener );
412
+ context .refresh ();
413
+
414
+ MyEvent event1 = new MyEvent (context );
415
+ context .publishEvent (event1 );
416
+ context .publishEvent (new MyOtherEvent (context ));
417
+ MyEvent event2 = new MyEvent (context );
418
+ context .publishEvent (event2 );
419
+ assertSame (2 , seenEvents .size ());
420
+ assertTrue (seenEvents .contains (event1 ));
421
+ assertTrue (seenEvents .contains (event2 ));
422
+
423
+ context .close ();
424
+ }
425
+
382
426
@ Test
383
427
public void beanPostProcessorPublishesEvents () {
384
428
GenericApplicationContext context = new GenericApplicationContext ();
@@ -415,7 +459,7 @@ public MyOtherEvent(Object source) {
415
459
416
460
public static class MyOrderedListener1 implements ApplicationListener <ApplicationEvent >, Ordered {
417
461
418
- public final Set <ApplicationEvent > seenEvents = new HashSet <ApplicationEvent >();
462
+ public final Set <ApplicationEvent > seenEvents = new HashSet <>();
419
463
420
464
@ Override
421
465
public void onApplicationEvent (ApplicationEvent event ) {
@@ -459,7 +503,7 @@ public void onApplicationEvent(MyEvent event) {
459
503
460
504
public static class MyPayloadListener implements ApplicationListener <PayloadApplicationEvent > {
461
505
462
- public final Set <Object > seenPayloads = new HashSet <Object >();
506
+ public final Set <Object > seenPayloads = new HashSet <>();
463
507
464
508
@ Override
465
509
public void onApplicationEvent (PayloadApplicationEvent event ) {
@@ -470,7 +514,7 @@ public void onApplicationEvent(PayloadApplicationEvent event) {
470
514
471
515
public static class MyNonSingletonListener implements ApplicationListener <ApplicationEvent > {
472
516
473
- public static final Set <ApplicationEvent > seenEvents = new HashSet <ApplicationEvent >();
517
+ public static final Set <ApplicationEvent > seenEvents = new HashSet <>();
474
518
475
519
@ Override
476
520
public void onApplicationEvent (ApplicationEvent event ) {
@@ -482,7 +526,7 @@ public void onApplicationEvent(ApplicationEvent event) {
482
526
@ Order (5 )
483
527
public static class MyOrderedListener3 implements ApplicationListener <ApplicationEvent > {
484
528
485
- public final Set <ApplicationEvent > seenEvents = new HashSet <ApplicationEvent >();
529
+ public final Set <ApplicationEvent > seenEvents = new HashSet <>();
486
530
487
531
@ Override
488
532
public void onApplicationEvent (ApplicationEvent event ) {
0 commit comments