33
33
import org .junit .jupiter .api .BeforeEach ;
34
34
import org .junit .jupiter .api .Test ;
35
35
import org .mockito .ArgumentCaptor ;
36
-
37
36
import org .springframework .beans .factory .BeanFactory ;
38
37
import org .springframework .core .convert .converter .Converter ;
39
38
import org .springframework .dao .DataAccessException ;
@@ -330,14 +329,13 @@ void appliesConverterToIterable() {
330
329
@ Test // GH-1323
331
330
void queryByListOfTuples () {
332
331
333
- String [][] tuples = {new String []{ "Albert" , "Einstein" }, new String []{ "Richard" , "Feynman" } };
332
+ String [][] tuples = { new String [] { "Albert" , "Einstein" }, new String [] { "Richard" , "Feynman" } };
334
333
335
334
SqlParameterSource parameterSource = forMethod ("findByListOfTuples" , List .class ) //
336
- .withArguments (Arrays .asList (tuples ))
335
+ .withArguments (Arrays .asList (tuples )) //
337
336
.extractParameterSource ();
338
337
339
- assertThat (parameterSource .getValue ("tuples" ))
340
- .asInstanceOf (LIST )
338
+ assertThat (parameterSource .getValue ("tuples" )).asInstanceOf (LIST ) //
341
339
.containsExactly (tuples );
342
340
343
341
assertThat (parameterSource .getSqlType ("tuples" )).isEqualTo (JdbcUtil .TYPE_UNKNOWN .getVendorTypeNumber ());
@@ -348,12 +346,38 @@ void queryByListOfConvertableTuples() {
348
346
349
347
SqlParameterSource parameterSource = forMethod ("findByListOfTuples" , List .class ) //
350
348
.withCustomConverters (DirectionToIntegerConverter .INSTANCE ) //
351
- .withArguments (Arrays .asList (new Object []{Direction .LEFT , "Einstein" }, new Object []{Direction .RIGHT , "Feynman" }))
349
+ .withArguments (
350
+ Arrays .asList (new Object [] { Direction .LEFT , "Einstein" }, new Object [] { Direction .RIGHT , "Feynman" }))
352
351
.extractParameterSource ();
353
352
354
- assertThat (parameterSource .getValue ("tuples" ))
355
- .asInstanceOf (LIST )
356
- .containsExactly (new Object [][]{new Object []{-1 , "Einstein" }, new Object []{1 , "Feynman" }});
353
+ assertThat (parameterSource .getValue ("tuples" )).asInstanceOf (LIST ) //
354
+ .containsExactly (new Object [][] { new Object [] { -1 , "Einstein" }, new Object [] { 1 , "Feynman" } });
355
+ }
356
+
357
+ @ Test // GH-619
358
+ void spelCanBeUsedInsideQueries () {
359
+
360
+ JdbcQueryMethod queryMethod = createMethod ("findBySpelExpression" , Object .class );
361
+
362
+ List <EvaluationContextExtension > list = new ArrayList <>();
363
+ list .add (new MyEvaluationContextProvider ());
364
+ QueryMethodEvaluationContextProvider evaluationContextProviderImpl = new ExtensionAwareQueryMethodEvaluationContextProvider (
365
+ list );
366
+
367
+ StringBasedJdbcQuery sut = new StringBasedJdbcQuery (queryMethod , operations , defaultRowMapper , converter ,
368
+ evaluationContextProviderImpl );
369
+
370
+ ArgumentCaptor <SqlParameterSource > paramSource = ArgumentCaptor .forClass (SqlParameterSource .class );
371
+ ArgumentCaptor <String > query = ArgumentCaptor .forClass (String .class );
372
+
373
+ sut .execute (new Object [] { "myValue" });
374
+
375
+ verify (this .operations ).queryForObject (query .capture (), paramSource .capture (), any (RowMapper .class ));
376
+
377
+ assertThat (query .getValue ())
378
+ .isEqualTo ("SELECT * FROM table WHERE c = :__$synthetic$__1 AND c2 = :__$synthetic$__2" );
379
+ assertThat (paramSource .getValue ().getValue ("__$synthetic$__1" )).isEqualTo ("test-value1" );
380
+ assertThat (paramSource .getValue ().getValue ("__$synthetic$__2" )).isEqualTo ("test-value2" );
357
381
}
358
382
359
383
QueryFixture forMethod (String name , Class ... paramTypes ) {
@@ -486,32 +510,6 @@ interface MyRepository extends Repository<Object, Long> {
486
510
Object findByListOfTuples (@ Param ("tuples" ) List <Object []> tuples );
487
511
}
488
512
489
- @ Test // GH-619
490
- public void spelCanBeUsedInsideQueries () {
491
-
492
- JdbcQueryMethod queryMethod = createMethod ("findBySpelExpression" , Object .class );
493
-
494
- List <EvaluationContextExtension > list = new ArrayList <>();
495
- list .add (new MyEvaluationContextProvider ());
496
- QueryMethodEvaluationContextProvider evaluationContextProviderImpl = new ExtensionAwareQueryMethodEvaluationContextProvider (
497
- list );
498
-
499
- StringBasedJdbcQuery sut = new StringBasedJdbcQuery (queryMethod , operations , defaultRowMapper , converter ,
500
- evaluationContextProviderImpl );
501
-
502
- ArgumentCaptor <SqlParameterSource > paramSource = ArgumentCaptor .forClass (SqlParameterSource .class );
503
- ArgumentCaptor <String > query = ArgumentCaptor .forClass (String .class );
504
-
505
- sut .execute (new Object [] { "myValue" });
506
-
507
- verify (this .operations ).queryForObject (query .capture (), paramSource .capture (), any (RowMapper .class ));
508
-
509
- assertThat (query .getValue ())
510
- .isEqualTo ("SELECT * FROM table WHERE c = :__$synthetic$__1 AND c2 = :__$synthetic$__2" );
511
- assertThat (paramSource .getValue ().getValue ("__$synthetic$__1" )).isEqualTo ("test-value1" );
512
- assertThat (paramSource .getValue ().getValue ("__$synthetic$__2" )).isEqualTo ("test-value2" );
513
- }
514
-
515
513
private static class CustomRowMapper implements RowMapper <Object > {
516
514
517
515
@ Override
0 commit comments