@@ -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 ();
0 commit comments