@@ -379,6 +379,50 @@ public void innerBeanAsListener() {
379379 context .close ();
380380 }
381381
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+
382426 @ Test
383427 public void beanPostProcessorPublishesEvents () {
384428 GenericApplicationContext context = new GenericApplicationContext ();
@@ -415,7 +459,7 @@ public MyOtherEvent(Object source) {
415459
416460 public static class MyOrderedListener1 implements ApplicationListener <ApplicationEvent >, Ordered {
417461
418- public final Set <ApplicationEvent > seenEvents = new HashSet <ApplicationEvent >();
462+ public final Set <ApplicationEvent > seenEvents = new HashSet <>();
419463
420464 @ Override
421465 public void onApplicationEvent (ApplicationEvent event ) {
@@ -459,7 +503,7 @@ public void onApplicationEvent(MyEvent event) {
459503
460504 public static class MyPayloadListener implements ApplicationListener <PayloadApplicationEvent > {
461505
462- public final Set <Object > seenPayloads = new HashSet <Object >();
506+ public final Set <Object > seenPayloads = new HashSet <>();
463507
464508 @ Override
465509 public void onApplicationEvent (PayloadApplicationEvent event ) {
@@ -470,7 +514,7 @@ public void onApplicationEvent(PayloadApplicationEvent event) {
470514
471515 public static class MyNonSingletonListener implements ApplicationListener <ApplicationEvent > {
472516
473- public static final Set <ApplicationEvent > seenEvents = new HashSet <ApplicationEvent >();
517+ public static final Set <ApplicationEvent > seenEvents = new HashSet <>();
474518
475519 @ Override
476520 public void onApplicationEvent (ApplicationEvent event ) {
@@ -482,7 +526,7 @@ public void onApplicationEvent(ApplicationEvent event) {
482526 @ Order (5 )
483527 public static class MyOrderedListener3 implements ApplicationListener <ApplicationEvent > {
484528
485- public final Set <ApplicationEvent > seenEvents = new HashSet <ApplicationEvent >();
529+ public final Set <ApplicationEvent > seenEvents = new HashSet <>();
486530
487531 @ Override
488532 public void onApplicationEvent (ApplicationEvent event ) {
0 commit comments