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