@@ -194,57 +194,85 @@ void pageQueryNotSupported() {
194
194
@ Test // GH-1212
195
195
void convertsEnumCollectionParameterIntoStringCollectionParameter () {
196
196
197
- JdbcQueryMethod queryMethod = createMethod ("findByEnumTypeIn" , Set .class );
198
- BasicJdbcConverter converter = new BasicJdbcConverter (mock (RelationalMappingContext .class ),
199
- mock (RelationResolver .class ));
200
- StringBasedJdbcQuery query = new StringBasedJdbcQuery (queryMethod , operations , result -> mock (RowMapper .class ),
201
- converter , evaluationContextProvider );
197
+ SqlParameterSource sqlParameterSource = forMethod ("findByEnumTypeIn" , Set .class )
198
+ .withArguments (Set .of (Direction .LEFT , Direction .RIGHT )).extractParameterSource ();
202
199
203
- query .execute (new Object [] { Set .of (Direction .LEFT , Direction .RIGHT ) });
204
-
205
- ArgumentCaptor <SqlParameterSource > captor = ArgumentCaptor .forClass (SqlParameterSource .class );
206
- verify (operations ).query (anyString (), captor .capture (), any (ResultSetExtractor .class ));
207
-
208
- SqlParameterSource sqlParameterSource = captor .getValue ();
209
200
assertThat (sqlParameterSource .getValue ("directions" )).asList ().containsExactlyInAnyOrder ("LEFT" , "RIGHT" );
210
201
}
211
202
212
203
@ Test // GH-1212
213
204
void convertsEnumCollectionParameterUsingCustomConverterWhenRegisteredForType () {
214
205
215
- JdbcQueryMethod queryMethod = createMethod ("findByEnumTypeIn" , Set .class );
216
- BasicJdbcConverter converter = new BasicJdbcConverter (mock (RelationalMappingContext .class ),
217
- mock (RelationResolver .class ),
218
- new JdbcCustomConversions (List .of (DirectionToIntegerConverter .INSTANCE , IntegerToDirectionConverter .INSTANCE )),
219
- JdbcTypeFactory .unsupported (), IdentifierProcessing .ANSI );
220
- StringBasedJdbcQuery query = new StringBasedJdbcQuery (queryMethod , operations , result -> mock (RowMapper .class ),
221
- converter , evaluationContextProvider );
222
-
223
- query .execute (new Object [] { Set .of (Direction .LEFT , Direction .RIGHT ) });
224
-
225
- ArgumentCaptor <SqlParameterSource > captor = ArgumentCaptor .forClass (SqlParameterSource .class );
226
- verify (operations ).query (anyString (), captor .capture (), any (ResultSetExtractor .class ));
206
+ SqlParameterSource sqlParameterSource = forMethod ("findByEnumTypeIn" , Set .class ) //
207
+ .withCustomConverters (DirectionToIntegerConverter .INSTANCE , IntegerToDirectionConverter .INSTANCE )
208
+ .withArguments (Set .of (Direction .LEFT , Direction .RIGHT )) //
209
+ .extractParameterSource ();
227
210
228
- SqlParameterSource sqlParameterSource = captor .getValue ();
229
211
assertThat (sqlParameterSource .getValue ("directions" )).asList ().containsExactlyInAnyOrder (-1 , 1 );
230
212
}
231
213
214
+
232
215
@ Test // GH-1212
233
216
void doesNotConvertNonCollectionParameter () {
234
217
235
- JdbcQueryMethod queryMethod = createMethod ("findBySimpleValue" , Integer .class );
236
- BasicJdbcConverter converter = new BasicJdbcConverter (mock (RelationalMappingContext .class ),
237
- mock (RelationResolver .class ));
238
- StringBasedJdbcQuery query = new StringBasedJdbcQuery (queryMethod , operations , result -> mock (RowMapper .class ),
239
- converter , evaluationContextProvider );
218
+ SqlParameterSource sqlParameterSource = forMethod ("findBySimpleValue" , Integer .class ) //
219
+ .withArguments (1 ) //
220
+ .extractParameterSource ();
240
221
241
- query .execute (new Object [] { 1 });
222
+ assertThat (sqlParameterSource .getValue ("value" )).isEqualTo (1 );
223
+ }
242
224
243
- ArgumentCaptor <SqlParameterSource > captor = ArgumentCaptor .forClass (SqlParameterSource .class );
244
- verify (operations ).query (anyString (), captor .capture (), any (ResultSetExtractor .class ));
225
+ QueryFixture forMethod (String name , Class ... paramTypes ) {
226
+ return new QueryFixture (createMethod (name , paramTypes ));
227
+ }
245
228
246
- SqlParameterSource sqlParameterSource = captor .getValue ();
247
- assertThat (sqlParameterSource .getValue ("value" )).isEqualTo (1 );
229
+ private class QueryFixture {
230
+
231
+ private final JdbcQueryMethod method ;
232
+ private Object [] arguments ;
233
+ private BasicJdbcConverter converter ;
234
+
235
+ public QueryFixture (JdbcQueryMethod method ) {
236
+ this .method = method ;
237
+ }
238
+
239
+ public QueryFixture withArguments (Object ... arguments ) {
240
+
241
+ this .arguments = arguments ;
242
+
243
+ return this ;
244
+ }
245
+
246
+ public SqlParameterSource extractParameterSource () {
247
+
248
+ BasicJdbcConverter converter = this .converter == null //
249
+ ? new BasicJdbcConverter (mock (RelationalMappingContext .class ), //
250
+ mock (RelationResolver .class ))
251
+ : this .converter ;
252
+
253
+ StringBasedJdbcQuery query = new StringBasedJdbcQuery (method , operations , result -> mock (RowMapper .class ),
254
+ converter , evaluationContextProvider );
255
+
256
+ query .execute (arguments );
257
+
258
+ ArgumentCaptor <SqlParameterSource > captor = ArgumentCaptor .forClass (SqlParameterSource .class );
259
+ verify (operations ).query (anyString (), captor .capture (), any (ResultSetExtractor .class ));
260
+
261
+ return captor .getValue ();
262
+ }
263
+
264
+ public QueryFixture withConverter (BasicJdbcConverter converter ) {
265
+
266
+ this .converter = converter ;
267
+
268
+ return this ;
269
+ }
270
+
271
+ public QueryFixture withCustomConverters (Object ... converters ) {
272
+
273
+ return withConverter (new BasicJdbcConverter (mock (RelationalMappingContext .class ), mock (RelationResolver .class ),
274
+ new JdbcCustomConversions (List .of (converters )), JdbcTypeFactory .unsupported (), IdentifierProcessing .ANSI ));
275
+ }
248
276
}
249
277
250
278
private JdbcQueryMethod createMethod (String methodName , Class <?>... paramTypes ) {
0 commit comments