@@ -202,6 +202,10 @@ void spr14235AdaptsToCompletableFuture() {
202
202
assertThat (bean .findById ("tb2" ).join ()).isNotSameAs (tb );
203
203
assertThat (cache .get ("tb2" )).isNull ();
204
204
205
+ assertThat (bean .findByIdEmpty ("" ).join ()).isNull ();
206
+ assertThat (bean .findByIdEmpty ("" ).join ()).isNull ();
207
+ assertThat (cache .get ("" ).get ()).isNull ();
208
+
205
209
context .close ();
206
210
}
207
211
@@ -226,6 +230,10 @@ void spr14235AdaptsToCompletableFutureWithSync() throws Exception {
226
230
assertThat (bean .findById ("tb1" ).get ()).isSameAs (tb );
227
231
assertThat (cache .get ("tb1" ).get ()).isSameAs (tb );
228
232
233
+ assertThat (bean .findById ("" ).join ()).isNull ();
234
+ assertThat (bean .findById ("" ).join ()).isNull ();
235
+ assertThat (cache .get ("" ).get ()).isNull ();
236
+
229
237
context .close ();
230
238
}
231
239
@@ -257,6 +265,10 @@ void spr14235AdaptsToReactorMono() {
257
265
assertThat (bean .findById ("tb2" ).block ()).isNotSameAs (tb );
258
266
assertThat (cache .get ("tb2" )).isNull ();
259
267
268
+ assertThat (bean .findByIdEmpty ("" ).block ()).isNull ();
269
+ assertThat (bean .findByIdEmpty ("" ).block ()).isNull ();
270
+ assertThat (cache .get ("" ).get ()).isNull ();
271
+
260
272
context .close ();
261
273
}
262
274
@@ -281,6 +293,10 @@ void spr14235AdaptsToReactorMonoWithSync() {
281
293
assertThat (bean .findById ("tb1" ).block ()).isSameAs (tb );
282
294
assertThat (cache .get ("tb1" ).get ()).isSameAs (tb );
283
295
296
+ assertThat (bean .findById ("" ).block ()).isNull ();
297
+ assertThat (bean .findById ("" ).block ()).isNull ();
298
+ assertThat (cache .get ("" ).get ()).isNull ();
299
+
284
300
context .close ();
285
301
}
286
302
@@ -312,6 +328,10 @@ void spr14235AdaptsToReactorFlux() {
312
328
assertThat (bean .findById ("tb2" ).collectList ().block ()).isNotEqualTo (tb );
313
329
assertThat (cache .get ("tb2" )).isNull ();
314
330
331
+ assertThat (bean .findByIdEmpty ("" ).collectList ().block ()).isEmpty ();
332
+ assertThat (bean .findByIdEmpty ("" ).collectList ().block ()).isEmpty ();
333
+ assertThat (cache .get ("" ).get ()).isEqualTo (Collections .emptyList ());
334
+
315
335
context .close ();
316
336
}
317
337
@@ -336,6 +356,10 @@ void spr14235AdaptsToReactorFluxWithSync() {
336
356
assertThat (bean .findById ("tb1" ).collectList ().block ()).isEqualTo (tb );
337
357
assertThat (cache .get ("tb1" ).get ()).isEqualTo (tb );
338
358
359
+ assertThat (bean .findById ("" ).collectList ().block ()).isEmpty ();
360
+ assertThat (bean .findById ("" ).collectList ().block ()).isEmpty ();
361
+ assertThat (cache .get ("" ).get ()).isEqualTo (Collections .emptyList ());
362
+
339
363
context .close ();
340
364
}
341
365
@@ -568,6 +592,11 @@ public CompletableFuture<TestBean> findById(String id) {
568
592
return CompletableFuture .completedFuture (new TestBean (id ));
569
593
}
570
594
595
+ @ Cacheable (value = "itemCache" )
596
+ public CompletableFuture <TestBean > findByIdEmpty (String id ) {
597
+ return CompletableFuture .completedFuture (null );
598
+ }
599
+
571
600
@ CachePut (cacheNames = "itemCache" , key = "#item.name" )
572
601
public CompletableFuture <TestBean > insertItem (TestBean item ) {
573
602
return CompletableFuture .completedFuture (item );
@@ -584,7 +613,7 @@ public static class Spr14235FutureServiceSync {
584
613
585
614
@ Cacheable (value = "itemCache" , sync = true )
586
615
public CompletableFuture <TestBean > findById (String id ) {
587
- return CompletableFuture .completedFuture (new TestBean (id ));
616
+ return CompletableFuture .completedFuture (id . isEmpty () ? null : new TestBean (id ));
588
617
}
589
618
590
619
@ CachePut (cacheNames = "itemCache" , key = "#item.name" )
@@ -601,6 +630,11 @@ public Mono<TestBean> findById(String id) {
601
630
return Mono .just (new TestBean (id ));
602
631
}
603
632
633
+ @ Cacheable (value = "itemCache" )
634
+ public Mono <TestBean > findByIdEmpty (String id ) {
635
+ return Mono .empty ();
636
+ }
637
+
604
638
@ CachePut (cacheNames = "itemCache" , key = "#item.name" )
605
639
public Mono <TestBean > insertItem (TestBean item ) {
606
640
return Mono .just (item );
@@ -617,7 +651,7 @@ public static class Spr14235MonoServiceSync {
617
651
618
652
@ Cacheable (value = "itemCache" , sync = true )
619
653
public Mono <TestBean > findById (String id ) {
620
- return Mono .just (new TestBean (id ));
654
+ return ( id . isEmpty () ? Mono .empty () : Mono . just (new TestBean (id ) ));
621
655
}
622
656
623
657
@ CachePut (cacheNames = "itemCache" , key = "#item.name" )
@@ -636,6 +670,11 @@ public Flux<TestBean> findById(String id) {
636
670
return Flux .just (new TestBean (id ), new TestBean (id + (counter ++)));
637
671
}
638
672
673
+ @ Cacheable (value = "itemCache" )
674
+ public Flux <TestBean > findByIdEmpty (String id ) {
675
+ return Flux .empty ();
676
+ }
677
+
639
678
@ CachePut (cacheNames = "itemCache" , key = "#id" )
640
679
public Flux <TestBean > insertItem (String id , List <TestBean > item ) {
641
680
return Flux .fromIterable (item );
@@ -654,7 +693,7 @@ public static class Spr14235FluxServiceSync {
654
693
655
694
@ Cacheable (value = "itemCache" , sync = true )
656
695
public Flux <TestBean > findById (String id ) {
657
- return Flux .just (new TestBean (id ), new TestBean (id + (counter ++)));
696
+ return ( id . isEmpty () ? Flux .empty () : Flux . just (new TestBean (id ), new TestBean (id + (counter ++) )));
658
697
}
659
698
660
699
@ CachePut (cacheNames = "itemCache" , key = "#id" )
0 commit comments