diff --git a/src/test/java/org/apache/commons/dbcp2/TestBasicDataSource.java b/src/test/java/org/apache/commons/dbcp2/TestBasicDataSource.java index da9049459..8057d996d 100644 --- a/src/test/java/org/apache/commons/dbcp2/TestBasicDataSource.java +++ b/src/test/java/org/apache/commons/dbcp2/TestBasicDataSource.java @@ -25,7 +25,6 @@ import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.fail; import java.io.IOException; import java.lang.management.ManagementFactory; diff --git a/src/test/java/org/apache/commons/dbcp2/managed/TestConnectionWithNarayana.java b/src/test/java/org/apache/commons/dbcp2/managed/TestConnectionWithNarayana.java index 7ae6a4546..c53d32bd5 100644 --- a/src/test/java/org/apache/commons/dbcp2/managed/TestConnectionWithNarayana.java +++ b/src/test/java/org/apache/commons/dbcp2/managed/TestConnectionWithNarayana.java @@ -20,7 +20,6 @@ Licensed to the Apache Software Foundation (ASF) under one or more import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.fail; import java.sql.Connection; import java.sql.PreparedStatement; diff --git a/src/test/java/org/apache/commons/dbcp2/managed/TestManagedDataSourceInTx.java b/src/test/java/org/apache/commons/dbcp2/managed/TestManagedDataSourceInTx.java index c40705f8c..f83e54364 100644 --- a/src/test/java/org/apache/commons/dbcp2/managed/TestManagedDataSourceInTx.java +++ b/src/test/java/org/apache/commons/dbcp2/managed/TestManagedDataSourceInTx.java @@ -25,7 +25,6 @@ Licensed to the Apache Software Foundation (ASF) under one or more import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.fail; import java.sql.CallableStatement; import java.sql.Connection; diff --git a/src/test/java/org/apache/commons/dbcp2/managed/TestPoolableManagedConnection.java b/src/test/java/org/apache/commons/dbcp2/managed/TestPoolableManagedConnection.java index b7e01117c..3f3dd844e 100644 --- a/src/test/java/org/apache/commons/dbcp2/managed/TestPoolableManagedConnection.java +++ b/src/test/java/org/apache/commons/dbcp2/managed/TestPoolableManagedConnection.java @@ -20,8 +20,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.fail; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.sql.Connection; import java.sql.SQLException; @@ -125,7 +124,8 @@ public void testPoolableConnection() throws Exception { public void testReallyClose() throws Exception { assertEquals(0, pool.getNumActive()); // create a connection - // pool uses LocalXAConnectionFactory, which register the connection with the TransactionRegistry + // pool uses LocalXAConnectionFactory, which register the connection with the + // TransactionRegistry conn = pool.borrowObject(); assertEquals(1, pool.getNumActive()); assertNotNull(transactionRegistry.getXAResource(conn)); @@ -134,14 +134,10 @@ public void testReallyClose() throws Exception { poolableManagedConnection.close(); assertNotNull(transactionRegistry.getXAResource(conn)); assertEquals(1, pool.getNumActive()); - // this must close the managed connection, removing it from the transaction registry + // this must close the managed connection, removing it from the transaction + // registry poolableManagedConnection.reallyClose(); - try { - assertNull(transactionRegistry.getXAResource(conn)); - fail("Transaction registry was supposed to be empty now"); - } catch (final SQLException ignore) { - // ignore - } + assertThrows(SQLException.class, () -> transactionRegistry.getXAResource(conn), "Transaction registry was supposed to be empty now"); assertEquals(0, pool.getNumActive()); } } \ No newline at end of file