33
33
import org .mockito .junit .jupiter .MockitoExtension ;
34
34
import org .mockito .junit .jupiter .MockitoSettings ;
35
35
import org .mockito .quality .Strictness ;
36
+
36
37
import org .springframework .beans .factory .BeanFactory ;
37
38
import org .springframework .data .domain .Page ;
38
39
import org .springframework .data .domain .Pageable ;
47
48
import org .springframework .data .repository .core .support .DefaultRepositoryMetadata ;
48
49
import org .springframework .data .repository .query .QueryLookupStrategy ;
49
50
import org .springframework .data .repository .query .QueryLookupStrategy .Key ;
50
- import org .springframework .data .repository .query .QueryMethodEvaluationContextProvider ;
51
51
import org .springframework .data .repository .query .RepositoryQuery ;
52
+ import org .springframework .data .repository .query .ValueExpressionDelegate ;
52
53
53
54
/**
54
55
* Unit tests for {@link JpaQueryLookupStrategy}.
63
64
@ MockitoSettings (strictness = Strictness .LENIENT )
64
65
class JpaQueryLookupStrategyUnitTests {
65
66
66
- private static final QueryMethodEvaluationContextProvider EVALUATION_CONTEXT_PROVIDER = QueryMethodEvaluationContextProvider . DEFAULT ;
67
+ private static final ValueExpressionDelegate VALUE_EXPRESSION_DELEGATE = ValueExpressionDelegate . create () ;
67
68
68
69
@ Mock EntityManager em ;
69
70
@ Mock EntityManagerFactory emf ;
@@ -89,7 +90,7 @@ void setUp() {
89
90
void invalidAnnotatedQueryCausesException () throws Exception {
90
91
91
92
QueryLookupStrategy strategy = JpaQueryLookupStrategy .create (em , queryMethodFactory , Key .CREATE_IF_NOT_FOUND ,
92
- EVALUATION_CONTEXT_PROVIDER , new BeanFactoryQueryRewriterProvider (beanFactory ), EscapeCharacter .DEFAULT );
93
+ VALUE_EXPRESSION_DELEGATE , new BeanFactoryQueryRewriterProvider (beanFactory ), EscapeCharacter .DEFAULT );
93
94
Method method = UserRepository .class .getMethod ("findByFoo" , String .class );
94
95
RepositoryMetadata metadata = new DefaultRepositoryMetadata (UserRepository .class );
95
96
@@ -101,7 +102,7 @@ void invalidAnnotatedQueryCausesException() throws Exception {
101
102
void considersNamedCountQuery () throws Exception {
102
103
103
104
QueryLookupStrategy strategy = JpaQueryLookupStrategy .create (em , queryMethodFactory , Key .CREATE_IF_NOT_FOUND ,
104
- EVALUATION_CONTEXT_PROVIDER , new BeanFactoryQueryRewriterProvider (beanFactory ), EscapeCharacter .DEFAULT );
105
+ VALUE_EXPRESSION_DELEGATE , new BeanFactoryQueryRewriterProvider (beanFactory ), EscapeCharacter .DEFAULT );
105
106
106
107
when (namedQueries .hasQuery ("foo.count" )).thenReturn (true );
107
108
when (namedQueries .getQuery ("foo.count" )).thenReturn ("select count(foo) from Foo foo" );
@@ -123,7 +124,7 @@ void considersNamedCountQuery() throws Exception {
123
124
void considersNamedCountOnStringQueryQuery () throws Exception {
124
125
125
126
QueryLookupStrategy strategy = JpaQueryLookupStrategy .create (em , queryMethodFactory , Key .CREATE_IF_NOT_FOUND ,
126
- EVALUATION_CONTEXT_PROVIDER , new BeanFactoryQueryRewriterProvider (beanFactory ), EscapeCharacter .DEFAULT );
127
+ VALUE_EXPRESSION_DELEGATE , new BeanFactoryQueryRewriterProvider (beanFactory ), EscapeCharacter .DEFAULT );
127
128
128
129
when (namedQueries .hasQuery ("foo.count" )).thenReturn (true );
129
130
when (namedQueries .getQuery ("foo.count" )).thenReturn ("select count(foo) from Foo foo" );
@@ -142,7 +143,7 @@ void considersNamedCountOnStringQueryQuery() throws Exception {
142
143
void prefersDeclaredQuery () throws Exception {
143
144
144
145
QueryLookupStrategy strategy = JpaQueryLookupStrategy .create (em , queryMethodFactory , Key .CREATE_IF_NOT_FOUND ,
145
- EVALUATION_CONTEXT_PROVIDER , new BeanFactoryQueryRewriterProvider (beanFactory ), EscapeCharacter .DEFAULT );
146
+ VALUE_EXPRESSION_DELEGATE , new BeanFactoryQueryRewriterProvider (beanFactory ), EscapeCharacter .DEFAULT );
146
147
Method method = UserRepository .class .getMethod ("annotatedQueryWithQueryAndQueryName" );
147
148
RepositoryMetadata metadata = new DefaultRepositoryMetadata (UserRepository .class );
148
149
@@ -155,7 +156,7 @@ void prefersDeclaredQuery() throws Exception {
155
156
void namedQueryWithSortShouldThrowIllegalStateException () throws NoSuchMethodException {
156
157
157
158
QueryLookupStrategy strategy = JpaQueryLookupStrategy .create (em , queryMethodFactory , Key .CREATE_IF_NOT_FOUND ,
158
- EVALUATION_CONTEXT_PROVIDER , new BeanFactoryQueryRewriterProvider (beanFactory ), EscapeCharacter .DEFAULT );
159
+ VALUE_EXPRESSION_DELEGATE , new BeanFactoryQueryRewriterProvider (beanFactory ), EscapeCharacter .DEFAULT );
159
160
160
161
Method method = UserRepository .class .getMethod ("customNamedQuery" , String .class , Sort .class );
161
162
RepositoryMetadata metadata = new DefaultRepositoryMetadata (UserRepository .class );
@@ -180,7 +181,7 @@ void noQueryShouldNotBeInvoked() {
180
181
void customQueryWithQuestionMarksShouldWork () throws NoSuchMethodException {
181
182
182
183
QueryLookupStrategy strategy = JpaQueryLookupStrategy .create (em , queryMethodFactory , Key .CREATE_IF_NOT_FOUND ,
183
- EVALUATION_CONTEXT_PROVIDER , new BeanFactoryQueryRewriterProvider (beanFactory ), EscapeCharacter .DEFAULT );
184
+ VALUE_EXPRESSION_DELEGATE , new BeanFactoryQueryRewriterProvider (beanFactory ), EscapeCharacter .DEFAULT );
184
185
185
186
Method namedMethod = UserRepository .class .getMethod ("customQueryWithQuestionMarksAndNamedParam" , String .class );
186
187
RepositoryMetadata namedMetadata = new DefaultRepositoryMetadata (UserRepository .class );
0 commit comments