10
10
import java .sql .Clob ;
11
11
import java .sql .SQLException ;
12
12
import java .util .ArrayList ;
13
- import java .util .Arrays ;
14
13
import java .util .HashMap ;
15
14
import java .util .IdentityHashMap ;
16
15
import java .util .Iterator ;
37
36
import org .hibernate .orm .test .sql .hand .TextHolder ;
38
37
import org .hibernate .query .NativeQuery ;
39
38
import org .hibernate .query .Query ;
40
- import org .hibernate .query .ResultListTransformer ;
41
39
import org .hibernate .transform .ResultTransformer ;
42
40
import org .hibernate .transform .Transformers ;
43
41
import org .hibernate .type .StandardBasicTypes ;
56
54
import jakarta .persistence .PersistenceException ;
57
55
58
56
import static org .hibernate .testing .orm .junit .ExtraAssertions .assertClassAssignability ;
57
+ import static org .junit .jupiter .api .Assertions .assertArrayEquals ;
59
58
import static org .junit .jupiter .api .Assertions .assertEquals ;
60
59
import static org .junit .jupiter .api .Assertions .assertFalse ;
61
60
import static org .junit .jupiter .api .Assertions .assertNotNull ;
@@ -218,18 +217,15 @@ public void testSQLQueryInterface(SessionFactoryScope scope) {
218
217
" left outer join EMPLOYMENT emp on org.orgid = emp.employer, ORGANIZATION org2" )
219
218
.addEntity ("org" , Organization .class )
220
219
.addJoin ("emp" , "org.employments" )
221
- .setResultListTransformer ( new ResultListTransformer () {
222
- @ Override
223
- public List transformList (List list ) {
224
- List <Object > result = new ArrayList <>( list .size () );
225
- Map <Object , Object > distinct = new IdentityHashMap <>();
226
- for ( Object entity : list ) {
227
- if ( distinct .put ( entity , entity ) == null ) {
228
- result .add ( entity );
229
- }
220
+ .setResultListTransformer ( list -> {
221
+ List <Object > result = new ArrayList <>( list .size () );
222
+ Map <Object , Object > distinct = new IdentityHashMap <>();
223
+ for ( Object entity : list ) {
224
+ if ( distinct .put ( entity , entity ) == null ) {
225
+ result .add ( entity );
230
226
}
231
- return result ;
232
227
}
228
+ return result ;
233
229
} )
234
230
.list ();
235
231
assertEquals ( 2 , l .size () );
@@ -305,7 +301,7 @@ public void testResultSetMappingDefinitionWithResultClass(SessionFactoryScope sc
305
301
}
306
302
307
303
@ Test
308
- public void testScalarValues (SessionFactoryScope scope ) throws Exception {
304
+ public void testScalarValues (SessionFactoryScope scope ) {
309
305
Organization ifa = new Organization ( "IFA" );
310
306
Organization jboss = new Organization ( "JBoss" );
311
307
@@ -338,11 +334,11 @@ public void testScalarValues(SessionFactoryScope scope) throws Exception {
338
334
Iterator iter = session .getNamedQuery ( "orgNamesAndOrgs" ).list ().iterator ();
339
335
Object [] o = ( Object [] ) iter .next ();
340
336
assertEquals ( 2 , o .length , "expecting 2 values" );
341
- assertEquals ( o [0 ], "IFA" );
342
- assertEquals ( ( ( Organization ) o [1 ] ).getName (), "IFA" );
337
+ assertEquals ( "IFA" , o [0 ] );
338
+ assertEquals ( "IFA" , ( ( Organization ) o [1 ] ).getName () );
343
339
o = ( Object [] ) iter .next ();
344
- assertEquals ( o [0 ], "JBoss" );
345
- assertEquals ( ( ( Organization ) o [1 ] ).getName (), "JBoss" );
340
+ assertEquals ( "JBoss" , o [0 ] );
341
+ assertEquals ( "JBoss" , ( ( Organization ) o [1 ] ).getName () );
346
342
}
347
343
);
348
344
@@ -354,13 +350,13 @@ public void testScalarValues(SessionFactoryScope scope) throws Exception {
354
350
assertEquals ( 2 , row .length , "expecting 2 values" );
355
351
assertEquals ( Organization .class , row [0 ].getClass (), "expecting non-scalar result first" );
356
352
assertEquals ( String .class , row [1 ].getClass (), "expecting scalar result second" );
357
- assertEquals ( ( ( Organization ) row [0 ] ).getName (), "IFA" );
358
- assertEquals ( row [1 ], "IFA" );
353
+ assertEquals ( "IFA" , ( ( Organization ) row [0 ] ).getName () );
354
+ assertEquals ( "IFA" , row [1 ] );
359
355
row = ( Object [] ) iter .next ();
360
356
assertEquals ( Organization .class , row [0 ].getClass (), "expecting non-scalar result first" );
361
357
assertEquals ( String .class , row [1 ].getClass (), "expecting scalar result second" );
362
- assertEquals ( ( ( Organization ) row [0 ] ).getName (), "JBoss" );
363
- assertEquals ( row [1 ], "JBoss" );
358
+ assertEquals ( "JBoss" , ( ( Organization ) row [0 ] ).getName () );
359
+ assertEquals ( "JBoss" , row [1 ] );
364
360
assertFalse ( iter .hasNext () );
365
361
}
366
362
);
@@ -369,10 +365,10 @@ public void testScalarValues(SessionFactoryScope scope) throws Exception {
369
365
session -> {
370
366
Iterator iter = session .getNamedQuery ( "orgIdsAndOrgNames" ).list ().iterator ();
371
367
Object [] o = ( Object [] ) iter .next ();
372
- assertEquals ( o [1 ], "IFA" );
368
+ assertEquals ( "IFA" , o [1 ] );
373
369
assertEquals ( o [0 ], idIfa );
374
370
o = ( Object [] ) iter .next ();
375
- assertEquals ( o [1 ], "JBoss" );
371
+ assertEquals ( "JBoss" , o [1 ] );
376
372
assertEquals ( o [0 ], idJBoss );
377
373
378
374
session .remove ( ifa );
@@ -598,7 +594,7 @@ public void testAutoDetectAliasing(SessionFactoryScope scope) {
598
594
Query queryWithCollection = session .getNamedQuery ("organizationEmploymentsExplicitAliases" );
599
595
queryWithCollection .setParameter ("id" , jboss .getId () );
600
596
list = queryWithCollection .list ();
601
- assertEquals (list .size (), 1 );
597
+ assertEquals ( 1 , list .size () );
602
598
603
599
session .clear ();
604
600
@@ -662,9 +658,9 @@ public void testAutoDetectAliasing(SessionFactoryScope scope) {
662
658
Object [] result = (Object []) session .getNamedQuery ( "spaceship" ).uniqueResult ();
663
659
assertEquals ( 3 , result .length , "expecting 3 result values" );
664
660
enterprise = ( SpaceShip ) result [0 ];
665
- assertTrue ( 50d == enterprise .getSpeed () );
666
- assertTrue ( 450d == extractDoubleValue ( result [1 ] ) );
667
- assertTrue ( 4500d == extractDoubleValue ( result [2 ] ) );
661
+ assertEquals ( 50d , enterprise .getSpeed () );
662
+ assertEquals ( 450d , extractDoubleValue ( result [1 ] ) );
663
+ assertEquals ( 4500d , extractDoubleValue ( result [2 ] ) );
668
664
session .remove ( enterprise );
669
665
}
670
666
);
@@ -754,14 +750,14 @@ public void testMixAndMatchEntityScalar(SessionFactoryScope scope) {
754
750
session -> {
755
751
Transaction t = session .beginTransaction ();
756
752
Speech speech = new Speech ();
757
- speech .setLength ( new Double ( 23d ) );
753
+ speech .setLength ( 23d );
758
754
speech .setName ( "Mine" );
759
755
session .persist ( speech );
760
756
session .flush ();
761
757
session .clear ();
762
758
763
759
List l = session .createNativeQuery ( "select name, id, flength, name as scalar_name from Speech" , "speech" ).list ();
764
- assertEquals ( l .size (), 1 );
760
+ assertEquals ( 1 , l .size () );
765
761
766
762
t .rollback ();
767
763
}
@@ -776,7 +772,7 @@ else if ( value instanceof BigDecimal ) {
776
772
return ( ( BigDecimal ) value ).doubleValue ();
777
773
}
778
774
else {
779
- return Double .valueOf ( value .toString () ). doubleValue ( );
775
+ return Double .parseDouble ( value .toString () );
780
776
}
781
777
}
782
778
@@ -900,7 +896,7 @@ public void testImageTypeInSQLQuery(SessionFactoryScope scope) {
900
896
throw new RuntimeException ( e );
901
897
}
902
898
}
903
- assertTrue ( Arrays . equals ( photo , photoRead ) );
899
+ assertArrayEquals ( photo , photoRead );
904
900
session .remove ( holder );
905
901
}
906
902
);
@@ -913,7 +909,7 @@ public void testEscapeColonInSQL(SessionFactoryScope scope) throws QueryExceptio
913
909
session -> {
914
910
NativeQuery query = session .createNativeQuery ( "SELECT @row \\ := 1" );
915
911
List list = query .list ();
916
- assertTrue ( list .get ( 0 ).toString (). equals ( "1" ) );
912
+ assertEquals ( "1" , list .get ( 0 ).toString () );
917
913
}
918
914
);
919
915
}
0 commit comments