Skip to content

Commit c893708

Browse files
committed
fix annoying assertions that test error message text
1 parent 5874eef commit c893708

File tree

3 files changed

+24
-30
lines changed

3 files changed

+24
-30
lines changed

hibernate-core/src/test/java/org/hibernate/orm/test/procedure/MySQLStoredProcedureTest.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -408,10 +408,7 @@ public void testStoredProcedureNullParameterHibernateWithoutSettingTheParameter(
408408
fail( "Should have thrown exception" );
409409
}
410410
catch (IllegalArgumentException e) {
411-
assertEquals(
412-
"The parameter at position [1] was not set! You need to call the setParameter method.",
413-
e.getMessage()
414-
);
411+
assertTrue( e.getMessage().contains( "parameter at position 1" ) );
415412
}
416413
} );
417414
}

hibernate-core/src/test/java/org/hibernate/orm/test/procedure/PostgreSQLFunctionProcedureTest.java

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@
3535
import java.time.ZoneOffset;
3636
import java.util.Set;
3737

38-
import static org.assertj.core.api.Assertions.assertThat;
38+
import static org.junit.jupiter.api.Assertions.assertEquals;
39+
import static org.junit.jupiter.api.Assertions.assertFalse;
3940
import static org.junit.jupiter.api.Assertions.assertThrows;
41+
import static org.junit.jupiter.api.Assertions.assertTrue;
4042
import static org.junit.jupiter.api.Assertions.fail;
4143

4244
/**
@@ -186,7 +188,7 @@ public void testFunctionProcedureOutParameter() {
186188

187189
query.execute();
188190
Long phoneCount = (Long) query.getSingleResult();
189-
assertThat( phoneCount ).isEqualTo( 2 );
191+
assertEquals( 2, phoneCount );
190192
} );
191193
}
192194

@@ -199,7 +201,7 @@ public void testFunctionProcedureRefCursor() {
199201

200202
query.setParameter( 1, 1L );
201203

202-
assertThat( query.getResultList() ).hasSize( 2 );
204+
assertEquals( 2, query.getResultList().size() );
203205
} );
204206
}
205207

@@ -213,7 +215,7 @@ public void testFunctionProcedureRefCursorOld() {
213215

214216
query.setParameter( 2, 1L );
215217

216-
assertThat( query.getResultList() ).hasSize( 2 );
218+
assertEquals( 2, query.getResultList().size() );
217219
} );
218220
}
219221

@@ -236,7 +238,7 @@ public void testFunctionWithJDBC() {
236238
}
237239
}
238240
} );
239-
assertThat( phoneCount ).isEqualTo( 2 );
241+
assertEquals( 2, phoneCount );
240242
} );
241243
}
242244

@@ -270,7 +272,7 @@ public void testSysRefCursorAsOutParameter() {
270272
catch (Exception e) {
271273
fail( e.getMessage() );
272274
}
273-
assertThat( value ).isEqualTo( 1 );
275+
assertEquals( 1, value );
274276

275277

276278
StoredProcedureQuery function = entityManager.createStoredProcedureQuery( "singleRefCursor" );
@@ -280,7 +282,7 @@ public void testSysRefCursorAsOutParameter() {
280282

281283
value = (Integer) function.getSingleResult();
282284

283-
assertThat( value ).isEqualTo( 1 );
285+
assertEquals( 1, value );
284286
} );
285287
}
286288

@@ -294,7 +296,7 @@ public void testSysRefCursorAsOutParameterOld() {
294296

295297
function.execute();
296298

297-
assertThat( function.hasMoreResults() ).isFalse();
299+
assertFalse( function.hasMoreResults() );
298300

299301
Integer value = null;
300302
try (ResultSet resultSet = (ResultSet) function.getOutputParameterValue( 1 )) {
@@ -306,7 +308,7 @@ public void testSysRefCursorAsOutParameterOld() {
306308
fail( e.getMessage() );
307309
}
308310

309-
assertThat( value ).isEqualTo( 1 );
311+
assertEquals( 1, value );
310312
} );
311313
}
312314

@@ -323,7 +325,7 @@ public void testFunctionProcedureNullParameterHibernate() {
323325

324326
Boolean result = (Boolean) procedureCall.getSingleResult();
325327

326-
assertThat( result ).isTrue();
328+
assertTrue( result );
327329
} );
328330

329331
inTransaction( entityManager -> {
@@ -335,7 +337,7 @@ public void testFunctionProcedureNullParameterHibernate() {
335337

336338
Boolean result = (Boolean) procedureCall.getSingleResult();
337339

338-
assertThat( result ).isFalse();
340+
assertFalse( result );
339341
} );
340342
}
341343

@@ -352,7 +354,7 @@ public void testFunctionProcedureNullParameterHibernateWithoutEnablePassingNulls
352354

353355
Boolean result = (Boolean) procedureCall.getSingleResult();
354356

355-
assertThat( result ).isTrue();
357+
assertTrue( result );
356358
} );
357359
}
358360

@@ -369,7 +371,6 @@ public void testFunctionProcedureNullParameterHibernateWithoutSettingTheParamete
369371
procedureCall.execute();
370372
} ) );
371373

372-
assertThat( exception.getMessage() )
373-
.isEqualTo( "The parameter named [param] was not set! You need to call the setParameter method." );
374+
assertTrue( exception.getMessage().contains( "parameter named 'param'" ) );
374375
}
375376
}

hibernate-core/src/test/java/org/hibernate/orm/test/procedure/PostgreSQLStoredProcedureTest.java

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import org.hibernate.testing.orm.junit.RequiresDialect;
2727
import org.hibernate.testing.orm.junit.Setting;
2828
import org.junit.jupiter.api.AfterEach;
29-
import org.junit.jupiter.api.Assertions;
3029
import org.junit.jupiter.api.BeforeEach;
3130
import org.junit.jupiter.api.Test;
3231

@@ -39,10 +38,10 @@
3938

4039
import static org.hamcrest.MatcherAssert.assertThat;
4140
import static org.hamcrest.core.Is.is;
42-
import static org.junit.Assert.assertEquals;
43-
import static org.junit.Assert.assertFalse;
44-
import static org.junit.Assert.assertTrue;
45-
import static org.junit.Assert.fail;
41+
import static org.junit.jupiter.api.Assertions.assertEquals;
42+
import static org.junit.jupiter.api.Assertions.assertFalse;
43+
import static org.junit.jupiter.api.Assertions.assertTrue;
44+
import static org.junit.jupiter.api.Assertions.fail;
4645

4746
/**
4847
* @author Vlad Mihalcea
@@ -230,10 +229,7 @@ public void testStoredProcedureNullParameterHibernateWithoutSettingTheParameter(
230229
fail( "Should have thrown exception" );
231230
}
232231
catch (IllegalArgumentException e) {
233-
assertEquals(
234-
"The parameter named [param] was not set! You need to call the setParameter method.",
235-
e.getMessage()
236-
);
232+
assertTrue( e.getMessage().contains( "parameter named 'param'" ) );
237233
}
238234
} );
239235
}
@@ -253,7 +249,7 @@ public void testStoredProcedureInAndOutAndRefCursorParameters(EntityManagerFacto
253249
query.execute();
254250
ResultSet rs = (ResultSet) query.getOutputParameterValue( "rec_out" );
255251
try {
256-
Assertions.assertTrue( rs.next() );
252+
assertTrue( rs.next() );
257253
assertThat( rs.getString( "street" ), is( STREET ) );
258254
assertThat( rs.getString( "city" ), is( CITY ) );
259255
assertThat( rs.getString( "zip" ), is( ZIP ) );
@@ -280,7 +276,7 @@ public void testStoredProcedureInAndOutAndRefCursorParametersDifferentRegistrati
280276
query.execute();
281277
ResultSet rs = (ResultSet) query.getOutputParameterValue( "rec_out" );
282278
try {
283-
Assertions.assertTrue( rs.next() );
279+
assertTrue( rs.next() );
284280
assertThat( rs.getString( "street" ), is( STREET ) );
285281
assertThat( rs.getString( "city" ), is( CITY ) );
286282
assertThat( rs.getString( "zip" ), is( ZIP ) );
@@ -307,7 +303,7 @@ public void testStoredProcedureInAndOutAndRefCursorParametersDifferentRegistrati
307303
query.execute();
308304
ResultSet rs = (ResultSet) query.getOutputParameterValue( "rec_out" );
309305
try {
310-
Assertions.assertTrue( rs.next() );
306+
assertTrue( rs.next() );
311307
assertThat( rs.getString( "street" ), is( STREET ) );
312308
assertThat( rs.getString( "city" ), is( CITY ) );
313309
assertThat( rs.getString( "zip" ), is( ZIP ) );

0 commit comments

Comments
 (0)