HHH-14764 Testsuite: AssertionErrors must not be caught
Fixes https://hibernate.atlassian.net/browse/HHH-14764
This commit is contained in:
parent
ebb91e44c3
commit
db3346962a
|
@ -13,6 +13,7 @@ import org.hibernate.internal.util.SerializationHelper;
|
|||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.fail;
|
||||
|
@ -313,28 +314,30 @@ public abstract class ConnectionManagementTestCase extends BaseNonConfigCoreFunc
|
|||
s.createQuery( "from Silly" ).list();
|
||||
fail( "allowed to create query on closed session" );
|
||||
}
|
||||
catch( Throwable ignore ) {
|
||||
catch (AssertionError testFailed) {
|
||||
throw testFailed;
|
||||
}
|
||||
catch (Throwable ignore) {
|
||||
}
|
||||
|
||||
try {
|
||||
s.getTransaction();
|
||||
fail( "allowed to access transaction on closed session" );
|
||||
}
|
||||
catch( Throwable ignore ) {
|
||||
}
|
||||
// you should be able to access the transaction on a closed EM. that is a change from what we used to do. we changed it
|
||||
// to better align with JPA.
|
||||
Transaction tran = s.getTransaction();
|
||||
assertNotNull( tran );
|
||||
|
||||
try {
|
||||
s.close();
|
||||
fail( "allowed to close already closed session" );
|
||||
}
|
||||
catch( Throwable ignore ) {
|
||||
}
|
||||
// Session implements both AutoCloseable and Closeable
|
||||
// Closable requires an idempotent behaviour, a closed resource must not throw an Exception
|
||||
// when close is called twice.
|
||||
s.close();
|
||||
|
||||
try {
|
||||
s.isDirty();
|
||||
fail( "allowed to check dirtiness of closed session" );
|
||||
}
|
||||
catch( Throwable ignore ) {
|
||||
catch (AssertionError testFailed) {
|
||||
throw testFailed;
|
||||
}
|
||||
catch (Throwable ignore) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -199,12 +199,25 @@ public class JPALockTest extends AbstractJPATest {
|
|||
t2.commit();
|
||||
fail( "optimistic lock should have failed" );
|
||||
}
|
||||
catch (Throwable ignore) {
|
||||
catch (Throwable t) {
|
||||
// expected behavior
|
||||
t2.rollback();
|
||||
try {
|
||||
t2.rollback();
|
||||
}
|
||||
catch (Throwable ignore) {
|
||||
// ignore
|
||||
}
|
||||
if ( t instanceof AssertionError ) {
|
||||
throw (AssertionError) t;
|
||||
}
|
||||
}
|
||||
finally {
|
||||
s2.close();
|
||||
try {
|
||||
s2.close();
|
||||
}
|
||||
catch (Throwable ignore) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
s1 = sessionFactory().openSession();
|
||||
|
|
|
@ -91,6 +91,9 @@ public class TransactionRollbackTest {
|
|||
if ( entityManager.getTransaction().isActive() ) {
|
||||
entityManager.getTransaction().rollback();
|
||||
}
|
||||
if ( e instanceof AssertionError ) {
|
||||
throw (AssertionError) e;
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
|
|
@ -160,22 +160,20 @@ public class MutableNaturalIdTest {
|
|||
.load();
|
||||
assertNotNull( loaded );
|
||||
}
|
||||
catch( HibernateException expected ) {
|
||||
session.getTransaction().markRollbackOnly();
|
||||
}
|
||||
catch( Throwable t ) {
|
||||
catch (Throwable t) {
|
||||
try {
|
||||
session.getTransaction().markRollbackOnly();
|
||||
}
|
||||
catch ( Throwable ignore ) {
|
||||
catch (Throwable ignore) {
|
||||
// ignore
|
||||
}
|
||||
if ( t instanceof AssertionError ) {
|
||||
throw (AssertionError) t;
|
||||
}
|
||||
fail();
|
||||
}
|
||||
}
|
||||
);
|
||||
} );
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testNonexistentNaturalIdCache(SessionFactoryScope scope) {
|
||||
final StatisticsImplementor statistics = scope.getSessionFactory().getStatistics();
|
||||
|
|
|
@ -257,6 +257,8 @@ public class HQLScrollFetchTest extends BaseCoreFunctionalTestCase {
|
|||
s.close();
|
||||
}
|
||||
|
||||
final String errMsg = "should have failed because data is ordered incorrectly.";
|
||||
|
||||
@Test
|
||||
public void testScrollOrderChildrenDesc() {
|
||||
Session s = openSession();
|
||||
|
@ -271,12 +273,16 @@ public class HQLScrollFetchTest extends BaseCoreFunctionalTestCase {
|
|||
while ( results.next() ) {
|
||||
list.add( results.get( ) );
|
||||
}
|
||||
|
||||
try {
|
||||
assertResultFromAllUsers( list );
|
||||
fail( "should have failed because data is ordered incorrectly." );
|
||||
fail( errMsg );
|
||||
}
|
||||
catch ( AssertionError ex ) {
|
||||
// expected
|
||||
if ( errMsg.equalsIgnoreCase( ex.getMessage() ) ) {
|
||||
throw ex;
|
||||
}
|
||||
// Other AssertionErrors expected
|
||||
}
|
||||
finally {
|
||||
s.close();
|
||||
|
@ -295,10 +301,13 @@ public class HQLScrollFetchTest extends BaseCoreFunctionalTestCase {
|
|||
List results = s.createQuery( QUERY + " order by c.name desc" ).list();
|
||||
try {
|
||||
assertResultFromAllUsers( results );
|
||||
fail( "should have failed because data is ordered incorrectly." );
|
||||
fail( errMsg );
|
||||
}
|
||||
catch ( AssertionError ex ) {
|
||||
// expected
|
||||
if ( errMsg.equalsIgnoreCase( ex.getMessage() ) ) {
|
||||
throw ex;
|
||||
}
|
||||
// Other AssertionErrors expected
|
||||
}
|
||||
finally {
|
||||
s.close();
|
||||
|
|
|
@ -142,6 +142,9 @@ public class HibernateCacheTest extends BaseFunctionalTest {
|
|||
catch ( Throwable ignore ) {
|
||||
}
|
||||
}
|
||||
if ( expected instanceof AssertionError ) {
|
||||
throw (AssertionError) expected;
|
||||
}
|
||||
}
|
||||
finally {
|
||||
if ( s != null && s.isOpen() ) {
|
||||
|
|
Loading…
Reference in New Issue