68
68
* @author Mark Paluch
69
69
* @author Erik Pellizzon
70
70
*/
71
+ @ SuppressWarnings ({"rawtypes" , "unchecked" })
71
72
@ ExtendWith (MockitoExtension .class )
72
73
@ MockitoSettings (strictness = Strictness .LENIENT )
73
74
class JpaQueryMethodUnitTests {
@@ -156,6 +157,8 @@ void returnsQueryIfAvailable() throws Exception {
156
157
void rejectsInvalidReturntypeOnPagebleFinder () {
157
158
158
159
when (metadata .getReturnedDomainClass (any ())).thenReturn ((Class ) User .class );
160
+ when (metadata .getDomainTypeInformation ()).thenReturn ((TypeInformation ) TypeInformation .of (User .class ));
161
+ when (metadata .getRepositoryInterface ()).thenReturn ((Class ) InvalidRepository .class );
159
162
160
163
assertThatIllegalStateException ()
161
164
.isThrownBy (() -> new JpaQueryMethod (invalidReturnType , metadata , factory , extractor ));
@@ -165,6 +168,8 @@ void rejectsInvalidReturntypeOnPagebleFinder() {
165
168
void rejectsPageableAndSortInFinderMethod () {
166
169
167
170
when (metadata .getReturnedDomainClass (any ())).thenReturn ((Class ) User .class );
171
+ when (metadata .getDomainTypeInformation ()).thenReturn ((TypeInformation ) TypeInformation .of (User .class ));
172
+ when (metadata .getRepositoryInterface ()).thenReturn ((Class ) InvalidRepository .class );
168
173
169
174
assertThatIllegalStateException ()
170
175
.isThrownBy (() -> new JpaQueryMethod (pageableAndSort , metadata , factory , extractor ));
@@ -318,8 +323,10 @@ void detectsLockAndQueryHintsOnIfUsedAsMetaAnnotation() throws Exception {
318
323
@ Test // DATAJPA-466
319
324
void shouldStoreJpa21FetchGraphInformationAsHint () {
320
325
321
- doReturn (User .class ).when (metadata ).getDomainType ();
322
- doReturn (User .class ).when (metadata ).getReturnedDomainClass (queryMethodWithCustomEntityFetchGraph );
326
+ when (metadata .getDomainType ()).thenReturn ((Class ) User .class );
327
+ when (metadata .getReturnedDomainClass (queryMethodWithCustomEntityFetchGraph )).thenReturn ((Class ) User .class );
328
+ when (metadata .getDomainTypeInformation ()).thenReturn ((TypeInformation ) TypeInformation .of (User .class ));
329
+ when (metadata .getRepositoryInterface ()).thenReturn ((Class ) InvalidRepository .class );
323
330
324
331
JpaQueryMethod method = new JpaQueryMethod (queryMethodWithCustomEntityFetchGraph , metadata , factory , extractor );
325
332
@@ -331,8 +338,10 @@ void shouldStoreJpa21FetchGraphInformationAsHint() {
331
338
@ Test // DATAJPA-612
332
339
void shouldFindEntityGraphAnnotationOnOverriddenSimpleJpaRepositoryMethod () throws Exception {
333
340
334
- doReturn (User .class ).when (metadata ).getDomainType ();
335
- doReturn (User .class ).when (metadata ).getReturnedDomainClass ((Method ) any ());
341
+ when (metadata .getDomainType ()).thenReturn ((Class ) User .class );
342
+ when (metadata .getReturnedDomainClass (any ())).thenReturn ((Class ) User .class );
343
+ when (metadata .getReturnedDomainClass (queryMethodWithCustomEntityFetchGraph )).thenReturn ((Class ) User .class );
344
+ when (metadata .getRepositoryInterface ()).thenReturn ((Class ) JpaRepositoryOverride .class );
336
345
337
346
JpaQueryMethod method = new JpaQueryMethod (JpaRepositoryOverride .class .getMethod ("findAll" ), metadata , factory ,
338
347
extractor );
@@ -345,8 +354,10 @@ void shouldFindEntityGraphAnnotationOnOverriddenSimpleJpaRepositoryMethod() thro
345
354
@ Test // DATAJPA-689
346
355
void shouldFindEntityGraphAnnotationOnOverriddenSimpleJpaRepositoryMethodFindOne () throws Exception {
347
356
348
- doReturn (User .class ).when (metadata ).getDomainType ();
349
- doReturn (User .class ).when (metadata ).getReturnedDomainClass ((Method ) any ());
357
+ when (metadata .getDomainType ()).thenReturn ((Class ) User .class );
358
+ when (metadata .getReturnedDomainClass (any ())).thenReturn ((Class ) User .class );
359
+ when (metadata .getDomainTypeInformation ()).thenReturn ((TypeInformation ) TypeInformation .of (User .class ));
360
+ when (metadata .getRepositoryInterface ()).thenReturn ((Class ) InvalidRepository .class );
350
361
351
362
JpaQueryMethod method = new JpaQueryMethod (JpaRepositoryOverride .class .getMethod ("findOne" , Integer .class ),
352
363
metadata , factory , extractor );
@@ -362,8 +373,10 @@ void shouldFindEntityGraphAnnotationOnOverriddenSimpleJpaRepositoryMethodFindOne
362
373
@ Test
363
374
void shouldFindEntityGraphAnnotationOnQueryMethodGetOneByWithDerivedName () throws Exception {
364
375
365
- doReturn (User .class ).when (metadata ).getDomainType ();
366
- doReturn (User .class ).when (metadata ).getReturnedDomainClass ((Method ) any ());
376
+ when (metadata .getDomainType ()).thenReturn ((Class ) User .class );
377
+ when (metadata .getDomainTypeInformation ()).thenReturn ((TypeInformation ) TypeInformation .of (User .class ));
378
+ when (metadata .getReturnedDomainClass (any ())).thenReturn ((Class ) User .class );
379
+ when (metadata .getRepositoryInterface ()).thenReturn ((Class ) JpaRepositoryOverride .class );
367
380
368
381
JpaQueryMethod method = new JpaQueryMethod (JpaRepositoryOverride .class .getMethod ("getOneById" , Integer .class ),
369
382
metadata , factory , extractor );
@@ -473,8 +486,10 @@ void usesAliasedValueForQueryNativeQuery() throws Exception {
473
486
@ Test // DATAJPA-871
474
487
void usesAliasedValueForEntityGraph () throws Exception {
475
488
476
- doReturn (User .class ).when (metadata ).getDomainType ();
477
- doReturn (User .class ).when (metadata ).getReturnedDomainClass ((Method ) any ());
489
+ when (metadata .getDomainType ()).thenReturn ((Class ) User .class );
490
+ when (metadata .getDomainTypeInformation ()).thenReturn ((TypeInformation ) TypeInformation .of (User .class ));
491
+ when (metadata .getReturnedDomainClass (any ())).thenReturn ((Class ) User .class );
492
+ when (metadata .getRepositoryInterface ()).thenReturn ((Class ) JpaRepositoryOverride .class );
478
493
479
494
JpaQueryMethod method = new JpaQueryMethod (
480
495
JpaRepositoryOverride .class .getMethod ("getOneWithCustomEntityGraphAnnotation" ), metadata , factory , extractor );
0 commit comments