25
25
import java .util .LinkedHashSet ;
26
26
import java .util .List ;
27
27
import java .util .Set ;
28
+ import java .util .concurrent .CompletableFuture ;
28
29
import java .util .concurrent .CountDownLatch ;
29
30
import java .util .concurrent .TimeUnit ;
30
31
import javax .annotation .PostConstruct ;
31
32
32
33
import org .junit .After ;
33
34
import org .junit .Ignore ;
34
35
import org .junit .Test ;
36
+ import reactor .core .publisher .Flux ;
37
+ import reactor .core .publisher .Mono ;
35
38
36
39
import org .springframework .aop .framework .Advised ;
37
40
import org .springframework .aop .support .AopUtils ;
61
64
import org .springframework .scheduling .annotation .EnableAsync ;
62
65
import org .springframework .stereotype .Component ;
63
66
import org .springframework .util .Assert ;
67
+ import org .springframework .util .concurrent .SettableListenableFuture ;
64
68
import org .springframework .validation .annotation .Validated ;
65
69
import org .springframework .validation .beanvalidation .MethodValidationPostProcessor ;
66
70
@@ -243,7 +247,69 @@ public void collectionReplyNullValue() {
243
247
}
244
248
245
249
@ Test
246
- public void eventListenerWorksWithSimpleInterfaceProxy () throws Exception {
250
+ public void listenableFutureReply () {
251
+ load (TestEventListener .class , ReplyEventListener .class );
252
+ SettableListenableFuture <String > future = new SettableListenableFuture <>();
253
+ future .set ("dummy" );
254
+ AnotherTestEvent event = new AnotherTestEvent (this , future );
255
+ ReplyEventListener replyEventListener = this .context .getBean (ReplyEventListener .class );
256
+ TestEventListener listener = this .context .getBean (TestEventListener .class );
257
+
258
+ this .eventCollector .assertNoEventReceived (listener );
259
+ this .eventCollector .assertNoEventReceived (replyEventListener );
260
+ this .context .publishEvent (event );
261
+ this .eventCollector .assertEvent (replyEventListener , event );
262
+ this .eventCollector .assertEvent (listener , "dummy" ); // reply
263
+ this .eventCollector .assertTotalEventsCount (2 );
264
+ }
265
+
266
+ @ Test
267
+ public void completableFutureReply () {
268
+ load (TestEventListener .class , ReplyEventListener .class );
269
+ AnotherTestEvent event = new AnotherTestEvent (this , CompletableFuture .completedFuture ("dummy" ));
270
+ ReplyEventListener replyEventListener = this .context .getBean (ReplyEventListener .class );
271
+ TestEventListener listener = this .context .getBean (TestEventListener .class );
272
+
273
+ this .eventCollector .assertNoEventReceived (listener );
274
+ this .eventCollector .assertNoEventReceived (replyEventListener );
275
+ this .context .publishEvent (event );
276
+ this .eventCollector .assertEvent (replyEventListener , event );
277
+ this .eventCollector .assertEvent (listener , "dummy" ); // reply
278
+ this .eventCollector .assertTotalEventsCount (2 );
279
+ }
280
+
281
+ @ Test
282
+ public void monoReply () {
283
+ load (TestEventListener .class , ReplyEventListener .class );
284
+ AnotherTestEvent event = new AnotherTestEvent (this , Mono .just ("dummy" ));
285
+ ReplyEventListener replyEventListener = this .context .getBean (ReplyEventListener .class );
286
+ TestEventListener listener = this .context .getBean (TestEventListener .class );
287
+
288
+ this .eventCollector .assertNoEventReceived (listener );
289
+ this .eventCollector .assertNoEventReceived (replyEventListener );
290
+ this .context .publishEvent (event );
291
+ this .eventCollector .assertEvent (replyEventListener , event );
292
+ this .eventCollector .assertEvent (listener , "dummy" ); // reply
293
+ this .eventCollector .assertTotalEventsCount (2 );
294
+ }
295
+
296
+ @ Test
297
+ public void fluxReply () {
298
+ load (TestEventListener .class , ReplyEventListener .class );
299
+ AnotherTestEvent event = new AnotherTestEvent (this , Flux .just ("dummy1" , "dummy2" ));
300
+ ReplyEventListener replyEventListener = this .context .getBean (ReplyEventListener .class );
301
+ TestEventListener listener = this .context .getBean (TestEventListener .class );
302
+
303
+ this .eventCollector .assertNoEventReceived (listener );
304
+ this .eventCollector .assertNoEventReceived (replyEventListener );
305
+ this .context .publishEvent (event );
306
+ this .eventCollector .assertEvent (replyEventListener , event );
307
+ this .eventCollector .assertEvent (listener , "dummy1" , "dummy2" ); // reply
308
+ this .eventCollector .assertTotalEventsCount (3 );
309
+ }
310
+
311
+ @ Test
312
+ public void eventListenerWorksWithSimpleInterfaceProxy () {
247
313
load (ScopedProxyTestBean .class );
248
314
249
315
SimpleService proxy = this .context .getBean (SimpleService .class );
@@ -260,7 +326,7 @@ public void eventListenerWorksWithSimpleInterfaceProxy() throws Exception {
260
326
}
261
327
262
328
@ Test
263
- public void eventListenerWorksWithAnnotatedInterfaceProxy () throws Exception {
329
+ public void eventListenerWorksWithAnnotatedInterfaceProxy () {
264
330
load (AnnotatedProxyTestBean .class );
265
331
266
332
AnnotatedSimpleService proxy = this .context .getBean (AnnotatedSimpleService .class );
@@ -277,7 +343,7 @@ public void eventListenerWorksWithAnnotatedInterfaceProxy() throws Exception {
277
343
}
278
344
279
345
@ Test
280
- public void eventListenerWorksWithCglibProxy () throws Exception {
346
+ public void eventListenerWorksWithCglibProxy () {
281
347
load (CglibProxyTestBean .class );
282
348
283
349
CglibProxyTestBean proxy = this .context .getBean (CglibProxyTestBean .class );
@@ -294,14 +360,14 @@ public void eventListenerWorksWithCglibProxy() throws Exception {
294
360
}
295
361
296
362
@ Test
297
- public void privateMethodOnCglibProxyFails () throws Exception {
363
+ public void privateMethodOnCglibProxyFails () {
298
364
assertThatExceptionOfType (BeanInitializationException .class ).isThrownBy (() ->
299
365
load (CglibProxyWithPrivateMethod .class ))
300
366
.withCauseInstanceOf (IllegalStateException .class );
301
367
}
302
368
303
369
@ Test
304
- public void eventListenerWorksWithCustomScope () throws Exception {
370
+ public void eventListenerWorksWithCustomScope () {
305
371
load (CustomScopeTestBean .class );
306
372
CustomScope customScope = new CustomScope ();
307
373
this .context .getBeanFactory ().registerScope ("custom" , customScope );
0 commit comments