Skip to content

Commit

Permalink
Use JUnit 5's assertThrows() and friends
Browse files Browse the repository at this point in the history
Remove unused imports
  • Loading branch information
garydgregory committed Dec 14, 2024
1 parent 96711d0 commit 374eb8b
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand All @@ -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());
}
}

0 comments on commit 374eb8b

Please sign in to comment.