16
16
package org .springframework .data .jpa .repository .query ;
17
17
18
18
import static org .assertj .core .api .Assertions .assertThat ;
19
+ import static org .assertj .core .api .Assertions .assertThatThrownBy ;
19
20
20
21
import java .util .Arrays ;
21
22
import java .util .List ;
24
25
import javax .persistence .EntityManagerFactory ;
25
26
import javax .sql .DataSource ;
26
27
28
+ import org .junit .Ignore ;
27
29
import org .junit .jupiter .api .BeforeEach ;
28
30
import org .junit .jupiter .api .Test ;
29
31
import org .junit .jupiter .api .extension .ExtendWith ;
52
54
* Verify that {@literal LIKE}s mixed with {@literal NULL}s work properly.
53
55
*
54
56
* @author Greg Turnquist
57
+ * @author Yuriy Tsarkov
55
58
*/
56
59
@ ExtendWith (SpringExtension .class )
57
60
@ ContextConfiguration (classes = QueryWithNullLikeHibernateIntegrationTests .Config .class )
58
61
@ Transactional
59
62
public class QueryWithNullLikeHibernateIntegrationTests {
60
63
61
- @ Autowired EmpoyeeWithNullLikeRepository repository ;
64
+ @ Autowired EmployeeWithNullLikeRepository repository ;
62
65
63
66
@ BeforeEach
64
67
void setUp () {
@@ -98,8 +101,7 @@ void customQueryWithNullMatch() {
98
101
99
102
List <EmployeeWithName > Employees = repository .customQueryWithNullableParam (null );
100
103
101
- assertThat (Employees ).extracting (EmployeeWithName ::getName ).containsExactlyInAnyOrder ("Frodo Baggins" ,
102
- "Bilbo Baggins" );
104
+ assertThat (Employees ).extracting (EmployeeWithName ::getName ).isEmpty ();
103
105
}
104
106
105
107
@ Test
@@ -128,6 +130,8 @@ void derivedQueryStartsWithWithEmptyStringMatch() {
128
130
}
129
131
130
132
@ Test
133
+ @ Ignore
134
+ @ Deprecated
131
135
void derivedQueryStartsWithWithNullMatch () {
132
136
133
137
List <EmployeeWithName > Employees = repository .findByNameStartsWith (null );
@@ -136,6 +140,13 @@ void derivedQueryStartsWithWithNullMatch() {
136
140
"Bilbo Baggins" );
137
141
}
138
142
143
+ @ Test // GH-2653
144
+ void derivedQueryStartsWithWithNullFail () {
145
+ assertThatThrownBy (() -> repository .findByNameStartsWith (null ))
146
+ .hasCauseExactlyInstanceOf (IllegalArgumentException .class )
147
+ .hasMessageStartingWith ("Value must not be null!" );
148
+ }
149
+
139
150
@ Test
140
151
void derivedQueryEndsWithWithMultipleMatch () {
141
152
@@ -163,6 +174,8 @@ void derivedQueryEndsWithWithEmptyStringMatch() {
163
174
}
164
175
165
176
@ Test
177
+ @ Ignore
178
+ @ Deprecated
166
179
void derivedQueryEndsWithWithNullMatch () {
167
180
168
181
List <EmployeeWithName > Employees = repository .findByNameEndsWith (null );
@@ -171,6 +184,14 @@ void derivedQueryEndsWithWithNullMatch() {
171
184
"Bilbo Baggins" );
172
185
}
173
186
187
+ @ Test // GH-2653
188
+ void derivedQueryEndsWithWithNullFail () {
189
+
190
+ assertThatThrownBy (() -> repository .findByNameStartsWith (null ))
191
+ .hasCauseExactlyInstanceOf (IllegalArgumentException .class )
192
+ .hasMessageStartingWith ("Value must not be null!" );
193
+ }
194
+
174
195
@ Test
175
196
void derivedQueryContainsWithMultipleMatch () {
176
197
@@ -198,6 +219,8 @@ void derivedQueryContainsWithEmptyStringMatch() {
198
219
}
199
220
200
221
@ Test
222
+ @ Ignore
223
+ @ Deprecated
201
224
void derivedQueryContainsWithNullMatch () {
202
225
203
226
List <EmployeeWithName > Employees = repository .findByNameContains (null );
@@ -206,6 +229,14 @@ void derivedQueryContainsWithNullMatch() {
206
229
"Bilbo Baggins" );
207
230
}
208
231
232
+ @ Test // GH-2653
233
+ void derivedQueryContainsWithNullFail () {
234
+
235
+ assertThatThrownBy (() -> repository .findByNameStartsWith (null ))
236
+ .hasCauseExactlyInstanceOf (IllegalArgumentException .class )
237
+ .hasMessageStartingWith ("Value must not be null!" );
238
+ }
239
+
209
240
@ Test
210
241
void derivedQueryLikeWithMultipleMatch () {
211
242
@@ -233,7 +264,7 @@ void derivedQueryLikeWithEmptyStringMatch() {
233
264
}
234
265
235
266
@ Transactional
236
- public interface EmpoyeeWithNullLikeRepository extends JpaRepository <EmployeeWithName , Integer > {
267
+ public interface EmployeeWithNullLikeRepository extends JpaRepository <EmployeeWithName , Integer > {
237
268
238
269
@ Query ("select e from EmployeeWithName e where e.name like %:partialName%" )
239
270
List <EmployeeWithName > customQueryWithNullableParam (@ Nullable @ Param ("partialName" ) String partialName );
@@ -248,7 +279,7 @@ public interface EmpoyeeWithNullLikeRepository extends JpaRepository<EmployeeWit
248
279
}
249
280
250
281
@ EnableJpaRepositories (considerNestedRepositories = true , //
251
- includeFilters = @ Filter (type = FilterType .ASSIGNABLE_TYPE , classes = EmpoyeeWithNullLikeRepository .class ))
282
+ includeFilters = @ Filter (type = FilterType .ASSIGNABLE_TYPE , classes = EmployeeWithNullLikeRepository .class ))
252
283
@ EnableTransactionManagement
253
284
static class Config {
254
285
0 commit comments