10000 Correct a bunch of warnings in NativeSQLQueriesTest · hibernate/hibernate-orm@d6c292e · GitHub
[go: up one dir, main page]

Skip to content

Commit d6c292e

Browse files
committed
Correct a bunch of warnings in NativeSQLQueriesTest
Signed-off-by: Jan Schatteman <jschatte@redhat.com>
1 parent e4e8482 commit d6c292e

File tree

1 file changed

+28
-32
lines changed

1 file changed

+28
-32
lines changed

hibernate-core/src/test/java/org/hibernate/orm/test/sql/hand/query/NativeSQLQueriesTest.java

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import java.sql.Clob;
1111
import java.sql.SQLException;
1212
import java.util.ArrayList;
13-
import java.util.Arrays;
1413
import java.util.HashMap;
1514
import java.util.IdentityHashMap;
1615
import java.util.Iterator;
@@ -37,7 +36,6 @@
3736
import org.hibernate.orm.test.sql.hand.TextHolder;
3837
import org.hibernate.query.NativeQuery;
3938
import org.hibernate.query.Query;
40-
import org.hibernate.query.ResultListTransformer;
4139
import org.hibernate.transform.ResultTransformer;
4240
import org.hibernate.transform.Transformers;
4341
import org.hibernate.type.StandardBasicTypes;
@@ -56,6 +54,7 @@
5654
import jakarta.persistence.PersistenceException;
5755

5856
import static org.hibernate.testing.orm.junit.ExtraAssertions.assertClassAssignability;
57+
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
5958
import static org.junit.jupiter.api.Assertions.assertEquals;
6059
import static org.junit.jupiter.api.Assertions.assertFalse;
6160
import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -218,18 +217,15 @@ public void testSQLQueryInterface(SessionFactoryScope scope) {
218217
" left outer join EMPLOYMENT emp on org.orgid = emp.employer, ORGANIZATION org2" )
219218
.addEntity("org", Organization.class)
220219
.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 );
230226
}
231-
return result;
232227
}
228+
return result;
233229
} )
234230
.list();
235231
assertEquals( 2, l.size() );
@@ -305,7 +301,7 @@ public void testResultSetMappingDefinitionWithResultClass(SessionFactoryScope sc
305301
}
306302

307303
@Test
308-
public void testScalarValues(SessionFactoryScope scope) throws Exception {
304+
public void testScalarValues(SessionFactoryScope scope) {
309305
Organization ifa = new Organization( "IFA" );
310306
Organization jboss = new Organization( "JBoss" );
311307

@@ -338,11 +334,11 @@ public void testScalarValues(SessionFactoryScope scope) throws Exception {
338334
Iterator iter = session.getNamedQuery( "orgNamesAndOrgs" ).list().iterator();
339335
Object[] o = ( Object[] ) iter.next();
340336
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() );
343339
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() );
346342
}
347343
);
348344

@@ -354,13 +350,13 @@ public void testScalarValues(SessionFactoryScope scope) throws Exception {
354350
assertEquals( 2, row.length, "expecting 2 values" );
355351
assertEquals( Organization.class, row[0].getClass(), "expecting non-scalar result first" );
356352
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] );
359355
row = ( Object[] ) iter.next();
360356
assertEquals( Organization.class, row[0].getClass(), "expecting non-scalar result first" );
361357
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] );
364360
assertFalse( iter.hasNext() );
365361
}
366362
);
@@ -369,10 +365,10 @@ public void testScalarValues(SessionFactoryScope scope) throws Exception {
369365
session -> {
370366
Iterator iter = session.getNamedQuery( "orgIdsAndOrgNames" ).list().iterator();
371367
Object[] o = ( Object[] ) iter.next();
372-
assertEquals( o[1], "IFA" );
368+
assertEquals( "IFA", o[1] );
373369
assertEquals( o[0], idIfa );
374370
o = ( Object[] ) iter.next();
375-
assertEquals( o[1], "JBoss" );
371+
assertEquals( "JBoss", o[1] );
376372
assertEquals( o[0], idJBoss );
377373

378374
session.remove( ifa );
@@ -598,7 +594,7 @@ public void testAutoDetectAliasing(SessionFactoryScope scope) {
598594
Query queryWithCollection = session.getNamedQuery("organizationEmploymentsExplicitAliases");
599595
queryWithCollection.setParameter("id", jboss.getId() );
600596
list = queryWithCollection.list();
601-
assertEquals(list.size(),1);
597+
assertEquals( 1, list.size() );
602598

603599
session.clear();
604600

@@ -662,9 +658,9 @@ public void testAutoDetectAliasing(SessionFactoryScope scope) {
662658
Object[] result = (Object[]) session.getNamedQuery( "spaceship" ).uniqueResult();
663659
assertEquals( 3, result.length, "expecting 3 result values" );
664660
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] ) );
668664
session.remove( enterprise );
669665
}
670666
);
@@ -754,14 +750,14 @@ public void testMixAndMatchEntityScalar(SessionFactoryScope scope) {
754750
session -> {
755751
Transaction t = session.beginTransaction();
756752
Speech speech = new Speech();
757-
speech.setLength( new Double( 23d ) );
753+
speech.setLength( 23d );
758754
speech.setName( "Mine" );
759755
session.persist( speech );
760756
session.flush();
761757
session.clear();
762758

763759
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() );
765761

766762
t.rollback();
767763
}
@@ -776,7 +772,7 @@ else if ( value instanceof BigDecimal ) {
776772
return ( ( BigDecimal ) value ).doubleValue();
777773
}
778774
else {
779-
return Double.valueOf( value.toString() ).doubleValue();
775+
return Double.parseDouble( value.toString() );
780776
}
781777
}
782778

@@ -900,7 +896,7 @@ public void testImageTypeInSQLQuery(SessionFactoryScope scope) {
900896
throw new RuntimeException( e );
901897
}
902898
}
903-
assertTrue( Arrays.equals( photo, photoRead ) );
899+
assertArrayEquals( photo, photoRead );
904900
session.remove( holder );
905901
}
906902
);
@@ -913,7 +909,7 @@ public void testEscapeColonInSQL(SessionFactoryScope scope) throws QueryExceptio
913909
session -> {
914910
NativeQuery query = session.createNativeQuery( "SELECT @row \\:= 1" );
915911
List list = query.list();
916-
assertTrue( list.get( 0 ).toString().equals( "1" ) );
912+
assertEquals( "1", list.get( 0 ).toString() );
917913
}
918914
);
919915
}

0 commit comments

Comments
 (0)
0