15
15
*/
16
16
package org .springframework .data .repository .aot .generate ;
17
17
18
- import static org .assertj .core .api .Assertions .* ;
19
- import static org .mockito .ArgumentMatchers .* ;
18
+ import static org .assertj .core .api .Assertions .assertThat ;
19
+ import static org .mockito .ArgumentMatchers .eq ;
20
20
21
21
import java .lang .reflect .Method ;
22
22
23
23
import org .junit .jupiter .api .Test ;
24
24
import org .mockito .Mockito ;
25
-
25
+ import org .springframework .data .domain .Limit ;
26
+ import org .springframework .data .domain .Page ;
26
27
import org .springframework .data .domain .Pageable ;
28
+ import org .springframework .data .domain .ScrollPosition ;
29
+ import org .springframework .data .domain .Window ;
30
+ import org .springframework .data .projection .SpelAwareProxyProjectionFactory ;
31
+ import org .springframework .data .repository .Repository ;
27
32
import org .springframework .data .repository .core .RepositoryInformation ;
33
+ import org .springframework .data .repository .core .support .AbstractRepositoryMetadata ;
34
+ import org .springframework .data .repository .query .DefaultParameters ;
28
35
import org .springframework .data .repository .query .QueryMethod ;
29
36
import org .springframework .data .util .TypeInformation ;
30
37
@@ -45,6 +52,28 @@ void suggestLocalVariableNameConsidersMethodArguments() throws NoSuchMethodExcep
45
52
assertThat (ctx .localVariable ("arg0" )).isNotIn ("arg0" , "arg1" , "arg2" );
46
53
}
47
54
55
+ @ Test // GH-3279
56
+ void returnsCorrectParameterNames () throws NoSuchMethodException {
57
+
58
+ AotQueryMethodGenerationContext ctx = ctxFor ("limitScrollPositionDynamicProjection" );
59
+
60
+ assertThat (ctx .getLimitParameterName ()).isEqualTo ("l" );
61
+ assertThat (ctx .getPageableParameterName ()).isNull ();
62
+ assertThat (ctx .getScrollPositionParameterName ()).isEqualTo ("sp" );
63
+ assertThat (ctx .getDynamicProjectionParameterName ()).isEqualTo ("projection" );
64
+ }
65
+
66
+ @ Test // GH-3279
67
+ void returnsCorrectParameterNameForPageable () throws NoSuchMethodException {
68
+
69
+ AotQueryMethodGenerationContext ctx = ctxFor ("pageable" );
70
+
71
+ assertThat (ctx .getLimitParameterName ()).isNull ();
72
+ assertThat (ctx .getPageableParameterName ()).isEqualTo ("p" );
73
+ assertThat (ctx .getScrollPositionParameterName ()).isNull ();
74
+ assertThat (ctx .getDynamicProjectionParameterName ()).isNull ();
75
+ }
76
+
48
77
AotQueryMethodGenerationContext ctxFor (String methodName ) throws NoSuchMethodException {
49
78
50
79
Method target = null ;
@@ -60,13 +89,21 @@ AotQueryMethodGenerationContext ctxFor(String methodName) throws NoSuchMethodExc
60
89
}
61
90
62
91
RepositoryInformation ri = Mockito .mock (RepositoryInformation .class );
63
- Mockito .doReturn (TypeInformation .of (target .getReturnType ())).when (ri ).getReturnType (eq (target ));
92
+ Mockito .doReturn (TypeInformation .of (String .class )).when (ri ).getReturnType (eq (target ));
93
+ Mockito .doReturn (TypeInformation .of (String .class )).when (ri ).getReturnedDomainTypeInformation (eq (target ));
64
94
65
- return new AotQueryMethodGenerationContext (ri , target , Mockito .mock (QueryMethod .class ),
95
+ return new AotQueryMethodGenerationContext (ri , target ,
96
+ new QueryMethod (target , AbstractRepositoryMetadata .getMetadata (DummyRepo .class ),
97
+ new SpelAwareProxyProjectionFactory (), DefaultParameters ::new ),
66
98
Mockito .mock (AotRepositoryFragmentMetadata .class ));
67
99
}
68
100
69
- private interface DummyRepo {
70
- String reservedParameterMethod (Object arg0 , Pageable arg1 , Object arg2 );
101
+ private interface DummyRepo extends Repository <String , Long > {
102
+
103
+ Page <String > reservedParameterMethod (Object arg0 , Pageable arg1 , Object arg2 );
104
+
105
+ <T > Window <T > limitScrollPositionDynamicProjection (Limit l , ScrollPosition sp , Class <T > projection );
106
+
107
+ Page <String > pageable (Pageable p );
71
108
}
72
109
}
0 commit comments