19
19
import static org .mockito .Mockito .*;
20
20
21
21
import io .reactivex .Flowable ;
22
+ import lombok .Getter ;
22
23
import reactor .core .publisher .Flux ;
23
24
import reactor .core .publisher .Mono ;
25
+ import reactor .test .StepVerifier ;
24
26
import rx .Observable ;
25
27
import rx .Single ;
26
28
@@ -308,6 +310,37 @@ void supportsFlowableProjections() throws Exception {
308
310
assertThat (content .get (0 )).isInstanceOf (SampleProjection .class );
309
311
}
310
312
313
+ @ Test // GH-2347
314
+ void findByListSkipsConversionIfTypeAlreadyMatches () throws Exception {
315
+
316
+ List <AbstractDto > result = getProcessor ("findAllAbstractDtos" )
317
+ .processResult (Collections .singletonList (new ConcreteDto ("Walter" , "White" )));
318
+
319
+ assertThat (result .get (0 )).isInstanceOf (ConcreteDto .class );
320
+ }
321
+
322
+ @ Test // GH-2347
323
+ void streamBySkipsConversionIfTypeAlreadyMatches () throws Exception {
324
+
325
+ Stream <AbstractDto > result = getProcessor ("streamAllAbstractDtos" )
326
+ .processResult (Stream .of (new ConcreteDto ("Walter" , "White" )));
327
+
328
+ assertThat (result .findFirst ().get ()).isInstanceOf (ConcreteDto .class );
329
+ }
330
+
331
+ @ Test // GH-2347
332
+ void findFluxSkipsConversionIfTypeAlreadyMatches () throws Exception {
333
+
334
+ Flux <AbstractDto > result = getProcessor ("findFluxOfAbstractDtos" )
335
+ .processResult (Flux .just (new ConcreteDto ("Walter" , "White" )));
336
+
337
+ result .as (StepVerifier ::create ) //
338
+ .consumeNextWith (actual -> {
339
+
340
+ assertThat (actual ).isInstanceOf (ConcreteDto .class );
341
+ }).verifyComplete ();
342
+ }
343
+
311
344
private static ResultProcessor getProcessor (String methodName , Class <?>... parameters ) throws Exception {
312
345
return getQueryMethod (methodName , parameters ).getResultProcessor ();
313
346
}
@@ -356,6 +389,12 @@ interface SampleRepository extends Repository<Sample, Long> {
356
389
Observable <SampleProjection > findObservableProjection ();
357
390
358
391
Flowable <SampleProjection > findFlowableProjection ();
392
+
393
+ List <AbstractDto > findAllAbstractDtos ();
394
+
395
+ Stream <AbstractDto > streamAllAbstractDtos ();
396
+
397
+ Flux <AbstractDto > findFluxOfAbstractDtos ();
359
398
}
360
399
361
400
static class Sample {
@@ -367,6 +406,23 @@ public Sample(String firstname, String lastname) {
367
406
}
368
407
}
369
408
409
+ @ Getter
410
+ static abstract class AbstractDto {
411
+ final String firstname , lastname ;
412
+
413
+ public AbstractDto (String firstname , String lastname ) {
414
+ this .firstname = firstname ;
415
+ this .lastname = lastname ;
416
+ }
417
+ }
418
+
419
+ static class ConcreteDto extends AbstractDto {
420
+
421
+ public ConcreteDto (String firstname , String lastname ) {
422
+ super (firstname , lastname );
423
+ }
424
+ }
425
+
370
426
static class SampleDto {}
371
427
372
428
@ lombok .Value
0 commit comments