Skip to content

Commit 0552d56

Browse files
committed
Use static imports only for JUnit
1 parent dc7cd66 commit 0552d56

12 files changed

Lines changed: 62 additions & 66 deletions

src/test/java/org/apache/commons/dbcp2/TestAbandonedBasicDataSource.java

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import java.time.Instant;
3535

3636
import org.apache.commons.pool2.KeyedObjectPool;
37-
import org.junit.jupiter.api.Assertions;
3837
import org.junit.jupiter.api.BeforeEach;
3938
import org.junit.jupiter.api.Test;
4039

@@ -60,7 +59,7 @@ private void checkLastUsedPreparedStatement(final PreparedStatement ps, final De
6059
ps.execute();
6160
assertAndReset(conn);
6261
try (ResultSet rs = ps.executeQuery()) {
63-
Assertions.assertNotNull(rs);
62+
assertNotNull(rs);
6463
}
6564
assertAndReset(conn);
6665
ps.executeUpdate();
@@ -82,7 +81,7 @@ private void checkLastUsedStatement(final Statement st, final DelegatingConnecti
8281
st.executeLargeBatch();
8382
assertAndReset(conn);
8483
try (ResultSet rs = st.executeQuery("")) {
85-
Assertions.assertNotNull(rs);
84+
assertNotNull(rs);
8685
}
8786
assertAndReset(conn);
8887
st.executeUpdate("");
@@ -103,7 +102,7 @@ private void checkLastUsedStatement(final Statement st, final DelegatingConnecti
103102

104103
private void createStatement(final Connection conn) throws Exception {
105104
final PreparedStatement ps = conn.prepareStatement("");
106-
Assertions.assertNotNull(ps);
105+
assertNotNull(ps);
107106
}
108107

109108
@Override
@@ -245,11 +244,11 @@ void testAbandonedStackTraces() throws Exception {
245244
@Test
246245
void testGarbageCollectorCleanUp01() throws Exception {
247246
try (DelegatingConnection<?> conn = (DelegatingConnection<?>) ds.getConnection()) {
248-
Assertions.assertEquals(0, conn.getTrace().size());
247+
assertEquals(0, conn.getTrace().size());
249248
createStatement(conn);
250-
Assertions.assertEquals(1, conn.getTrace().size());
249+
assertEquals(1, conn.getTrace().size());
251250
System.gc();
252-
Assertions.assertEquals(0, conn.getTrace().size());
251+
assertEquals(0, conn.getTrace().size());
253252
}
254253
}
255254

@@ -264,11 +263,11 @@ void testGarbageCollectorCleanUp02() throws Exception {
264263
final PoolableConnection poolableConn = (PoolableConnection) conn.getDelegate();
265264
final PoolingConnection poolingConn = (PoolingConnection) poolableConn.getDelegate();
266265
final KeyedObjectPool<PStmtKey, DelegatingPreparedStatement> gkop = poolingConn.getStatementPool();
267-
Assertions.assertEquals(0, conn.getTrace().size());
268-
Assertions.assertEquals(0, gkop.getNumActive());
266+
assertEquals(0, conn.getTrace().size());
267+
assertEquals(0, gkop.getNumActive());
269268
createStatement(conn);
270-
Assertions.assertEquals(1, conn.getTrace().size());
271-
Assertions.assertEquals(1, gkop.getNumActive());
269+
assertEquals(1, conn.getTrace().size());
270+
assertEquals(1, gkop.getNumActive());
272271
System.gc();
273272
// Finalization happens in a separate thread. Give the test time for
274273
// that to complete.
@@ -277,8 +276,8 @@ void testGarbageCollectorCleanUp02() throws Exception {
277276
Thread.sleep(100);
278277
count++;
279278
}
280-
Assertions.assertEquals(0, gkop.getNumActive());
281-
Assertions.assertEquals(0, conn.getTrace().size());
279+
assertEquals(0, gkop.getNumActive());
280+
assertEquals(0, conn.getTrace().size());
282281
}
283282

284283
/**
@@ -324,12 +323,12 @@ void testLastUsedLargePreparedStatementUse() throws Exception {
324323
final String querySQL = "SELECT 1 FROM DUAL";
325324
Thread.sleep(500);
326325
try (ResultSet rs = st.executeQuery(querySQL)) {
327-
Assertions.assertNotNull(rs); // Should reset lastUsed
326+
assertNotNull(rs); // Should reset lastUsed
328327
}
329328
Thread.sleep(800);
330329
try (final Connection conn2 = ds.getConnection()) { // triggers abandoned cleanup
331330
try (ResultSet rs = st.executeQuery(querySQL)) {
332-
Assertions.assertNotNull(rs); // Should still be OK
331+
assertNotNull(rs); // Should still be OK
333332
}
334333
}
335334
Thread.sleep(500);
@@ -386,10 +385,10 @@ void testLastUsedPreparedStatementUse() throws Exception {
386385
try (Connection conn1 = ds.getConnection(); Statement st = conn1.createStatement()) {
387386
final String querySQL = "SELECT 1 FROM DUAL";
388387
Thread.sleep(500);
389-
Assertions.assertNotNull(st.executeQuery(querySQL)); // Should reset lastUsed
388+
assertNotNull(st.executeQuery(querySQL)); // Should reset lastUsed
390389
Thread.sleep(800);
391390
final Connection conn2 = ds.getConnection(); // triggers abandoned cleanup
392-
Assertions.assertNotNull(st.executeQuery(querySQL)); // Should still be OK
391+
assertNotNull(st.executeQuery(querySQL)); // Should still be OK
393392
conn2.close();
394393
Thread.sleep(500);
395394
st.executeUpdate(""); // Should also reset

src/test/java/org/apache/commons/dbcp2/TestBasicDataSource.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import static org.junit.jupiter.api.Assertions.assertEquals;
2121
import static org.junit.jupiter.api.Assertions.assertFalse;
2222
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
23+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
2324
import static org.junit.jupiter.api.Assertions.assertNotNull;
2425
import static org.junit.jupiter.api.Assertions.assertNull;
2526
import static org.junit.jupiter.api.Assertions.assertSame;
@@ -48,7 +49,6 @@
4849
import javax.sql.DataSource;
4950

5051
import org.junit.jupiter.api.AfterEach;
51-
import org.junit.jupiter.api.Assertions;
5252
import org.junit.jupiter.api.BeforeEach;
5353
import org.junit.jupiter.api.Disabled;
5454
import org.junit.jupiter.api.Test;
@@ -738,7 +738,7 @@ void testMaxConnLifetimeExceeded() throws Exception {
738738
}
739739
assertEquals(0, ds.getNumIdle());
740740
final String message = StackMessageLog.popMessage();
741-
Assertions.assertNotNull(message);
741+
assertNotNull(message);
742742
assertTrue(message.indexOf("exceeds the maximum permitted value") > 0);
743743
} finally {
744744
StackMessageLog.clear();
@@ -789,7 +789,7 @@ void testMutateAbandonedConfig() throws Exception {
789789
try (BasicDataSource ds = BasicDataSourceFactory.createDataSource(properties)) {
790790
final boolean original = ds.getConnectionPool().getLogAbandoned();
791791
ds.setLogAbandoned(!original);
792-
Assertions.assertNotEquals(original, ds.getConnectionPool().getLogAbandoned());
792+
assertNotEquals(original, ds.getConnectionPool().getLogAbandoned());
793793
}
794794
}
795795

@@ -861,7 +861,7 @@ void testPoolCloseCheckedException() throws Exception {
861861
ds.close();
862862
// Exception must have been swallowed by the pool - verify it is logged
863863
final String message = StackMessageLog.popMessage();
864-
Assertions.assertNotNull(message);
864+
assertNotNull(message);
865865
assertTrue(message.indexOf("bang") > 0);
866866
} catch (final SQLException ex) {
867867
assertTrue(ex.getMessage().indexOf("Cannot close") > 0);
@@ -885,7 +885,7 @@ void testPoolCloseRTE() throws Exception {
885885
StackMessageLog.clear();
886886
ds.close();
887887
final String message = StackMessageLog.popMessage();
888-
Assertions.assertNotNull(message);
888+
assertNotNull(message);
889889
assertTrue(message.indexOf("boom") > 0);
890890
} catch (final IllegalStateException ex) {
891891
assertTrue(ex.getMessage().indexOf("boom") > 0); // RTE is not wrapped by BDS#close

src/test/java/org/apache/commons/dbcp2/TestDelegatingConnection.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import static org.junit.jupiter.api.Assertions.assertEquals;
2121
import static org.junit.jupiter.api.Assertions.assertFalse;
22+
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
2223
import static org.junit.jupiter.api.Assertions.assertNotNull;
2324
import static org.junit.jupiter.api.Assertions.assertNull;
2425
import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -31,7 +32,6 @@
3132

3233
import org.apache.commons.pool2.impl.GenericKeyedObjectPool;
3334
import org.junit.jupiter.api.AfterEach;
34-
import org.junit.jupiter.api.Assertions;
3535
import org.junit.jupiter.api.BeforeEach;
3636
import org.junit.jupiter.api.Test;
3737

@@ -287,8 +287,8 @@ void testPassivateWithResultSetCloseException() {
287287
testerResultSet.setSqlExceptionOnClose(true);
288288
delegatingConnection.addTrace(testerResultSet);
289289
final SQLException e = assertThrows(SQLException.class, delegatingConnection::passivate);
290-
Assertions.assertInstanceOf(SQLExceptionList.class, e);
291-
Assertions.assertEquals(1, ((SQLExceptionList) e).getCauseList().size());
290+
assertInstanceOf(SQLExceptionList.class, e);
291+
assertEquals(1, ((SQLExceptionList) e).getCauseList().size());
292292
}
293293

294294
@Test
@@ -298,17 +298,17 @@ void testPassivateWithResultSetCloseExceptionAndStatementCloseException() {
298298
delegatingConnection.addTrace(testerStatement);
299299
delegatingConnection.addTrace(testerResultSet);
300300
final SQLException e = assertThrows(SQLException.class, delegatingConnection::passivate);
301-
Assertions.assertInstanceOf(SQLExceptionList.class, e);
302-
Assertions.assertEquals(2, ((SQLExceptionList) e).getCauseList().size());
301+
assertInstanceOf(SQLExceptionList.class, e);
302+
assertEquals(2, ((SQLExceptionList) e).getCauseList().size());
303303
}
304304

305305
@Test
306306
void testPassivateWithStatementCloseException() {
307307
testerStatement.setSqlExceptionOnClose(true);
308308
delegatingConnection.addTrace(testerStatement);
309309
final SQLException e = assertThrows(SQLException.class, delegatingConnection::passivate);
310-
Assertions.assertInstanceOf(SQLExceptionList.class, e);
311-
Assertions.assertEquals(1, ((SQLExceptionList) e).getCauseList().size());
310+
assertInstanceOf(SQLExceptionList.class, e);
311+
assertEquals(1, ((SQLExceptionList) e).getCauseList().size());
312312
}
313313

314314
@Test

src/test/java/org/apache/commons/dbcp2/TestPStmtPooling.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import org.apache.commons.pool2.ObjectPool;
3636
import org.apache.commons.pool2.impl.GenericObjectPool;
3737
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
38-
import org.junit.jupiter.api.Assertions;
3938
import org.junit.jupiter.api.Test;
4039

4140
/**
@@ -93,7 +92,7 @@ void testBatchUpdate() throws Exception {
9392
ps.addBatch();
9493
ps.close();
9594
conn.close();
96-
Assertions.assertFalse(inner.isClosed());
95+
assertFalse(inner.isClosed());
9796
ds.close();
9897
}
9998

@@ -186,7 +185,7 @@ void testMultipleClose() throws Exception {
186185
final Connection conn2 = ds.getConnection();
187186
final PreparedStatement stmt2 = conn2.prepareStatement("select 1 from dual");
188187
// Confirm stmt2 now wraps the same PPS wrapped by stmt1
189-
Assertions.assertSame(pps1, getPoolablePreparedStatement(stmt2));
188+
assertSame(pps1, getPoolablePreparedStatement(stmt2));
190189
stmt1.close(); // close should not cascade to PPS that stmt1 used to wrap
191190
assertFalse(stmt2.isClosed());
192191
stmt2.executeQuery(); // wrapped PPS needs to work here - pre DBCP-414 fix this throws

src/test/java/org/apache/commons/dbcp2/TestPoolableConnection.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import static org.junit.jupiter.api.Assertions.assertFalse;
2121
import static org.junit.jupiter.api.Assertions.assertNotNull;
2222
import static org.junit.jupiter.api.Assertions.assertThrows;
23+
import static org.junit.jupiter.api.Assertions.assertTrue;
2324

2425
import java.sql.Connection;
2526
import java.sql.SQLException;
@@ -30,7 +31,6 @@
3031

3132
import org.apache.commons.pool2.impl.GenericObjectPool;
3233
import org.junit.jupiter.api.AfterEach;
33-
import org.junit.jupiter.api.Assertions;
3434
import org.junit.jupiter.api.BeforeEach;
3535
import org.junit.jupiter.api.Test;
3636

@@ -58,21 +58,21 @@ public void tearDown() {
5858

5959
@Test
6060
void testClosingWrappedInDelegate() throws Exception {
61-
Assertions.assertEquals(0, pool.getNumActive());
61+
assertEquals(0, pool.getNumActive());
6262

6363
final Connection conn = pool.borrowObject();
6464
final DelegatingConnection<Connection> outer = new DelegatingConnection<>(conn);
6565

66-
Assertions.assertFalse(outer.isClosed());
67-
Assertions.assertFalse(conn.isClosed());
68-
Assertions.assertEquals(1, pool.getNumActive());
66+
assertFalse(outer.isClosed());
67+
assertFalse(conn.isClosed());
68+
assertEquals(1, pool.getNumActive());
6969

7070
outer.close();
7171

72-
Assertions.assertTrue(outer.isClosed());
73-
Assertions.assertTrue(conn.isClosed());
74-
Assertions.assertEquals(0, pool.getNumActive());
75-
Assertions.assertEquals(1, pool.getNumIdle());
72+
assertTrue(outer.isClosed());
73+
assertTrue(conn.isClosed());
74+
assertEquals(0, pool.getNumActive());
75+
assertEquals(1, pool.getNumIdle());
7676
}
7777

7878
@Test

src/test/java/org/apache/commons/dbcp2/TestPoolingDataSource.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131

3232
import org.apache.commons.pool2.impl.GenericObjectPool;
3333
import org.junit.jupiter.api.AfterEach;
34-
import org.junit.jupiter.api.Assertions;
3534
import org.junit.jupiter.api.BeforeEach;
3635
import org.junit.jupiter.api.Test;
3736

@@ -191,8 +190,8 @@ void testPoolGuardConnectionWrapperEqualsSameDelegate() throws Exception {
191190
// Grab a new connection - should get c[0]'s closed connection
192191
// so should be delegate-equivalent
193192
final Connection con = newConnection();
194-
Assertions.assertNotEquals(c[0], con);
195-
Assertions.assertEquals(
193+
assertNotEquals(c[0], con);
194+
assertEquals(
196195
((DelegatingConnection<?>) c[0]).getInnermostDelegateInternal(),
197196
((DelegatingConnection<?>) con).getInnermostDelegateInternal());
198197
for (final Connection element : c) {

src/test/java/org/apache/commons/dbcp2/TestPoolingDriver.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
import org.apache.commons.pool2.impl.GenericObjectPool;
4242
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
4343
import org.junit.jupiter.api.AfterEach;
44-
import org.junit.jupiter.api.Assertions;
4544
import org.junit.jupiter.api.BeforeEach;
4645
import org.junit.jupiter.api.Test;
4746

@@ -103,7 +102,7 @@ void test1() {
103102
final GenericObjectPool<PoolableConnection> connectionPool = new GenericObjectPool<>(pcf);
104103
pcf.setPool(connectionPool);
105104
final DataSource ds = new PoolingDataSource<>(connectionPool);
106-
Assertions.assertNotNull(ds);
105+
assertNotNull(ds);
107106
}
108107

109108
@Test

src/test/java/org/apache/commons/dbcp2/TestSQLExceptionList.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@
1717

1818
package org.apache.commons.dbcp2;
1919

20+
import static org.junit.jupiter.api.Assertions.assertEquals;
21+
import static org.junit.jupiter.api.Assertions.assertNull;
22+
2023
import java.sql.SQLTransientException;
2124
import java.util.Collections;
2225
import java.util.List;
2326

24-
import org.junit.jupiter.api.Assertions;
2527
import org.junit.jupiter.api.Test;
2628

2729
public class TestSQLExceptionList {
@@ -31,15 +33,15 @@ void testCause() {
3133
final SQLTransientException cause = new SQLTransientException();
3234
final List<SQLTransientException> list = Collections.singletonList(cause);
3335
final SQLExceptionList sqlExceptionList = new SQLExceptionList(list);
34-
Assertions.assertEquals(cause, sqlExceptionList.getCause());
35-
Assertions.assertEquals(list, sqlExceptionList.getCauseList());
36+
assertEquals(cause, sqlExceptionList.getCause());
37+
assertEquals(list, sqlExceptionList.getCauseList());
3638
sqlExceptionList.printStackTrace();
3739
}
3840

3941
@Test
4042
void testNullCause() {
4143
final SQLExceptionList sqlExceptionList = new SQLExceptionList(null);
42-
Assertions.assertNull(sqlExceptionList.getCause());
43-
Assertions.assertNull(sqlExceptionList.getCauseList());
44+
assertNull(sqlExceptionList.getCause());
45+
assertNull(sqlExceptionList.getCauseList());
4446
}
4547
}

src/test/java/org/apache/commons/dbcp2/cpdsadapter/TestDriverAdapterCPDS.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
2121
import static org.junit.jupiter.api.Assertions.assertEquals;
22+
import static org.junit.jupiter.api.Assertions.assertFalse;
2223
import static org.junit.jupiter.api.Assertions.assertNotNull;
2324
import static org.junit.jupiter.api.Assertions.assertNull;
2425
import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -47,7 +48,6 @@
4748
import org.apache.commons.dbcp2.TestUtils;
4849
import org.apache.commons.dbcp2.datasources.SharedPoolDataSource;
4950
import org.apache.commons.pool2.impl.DefaultPooledObject;
50-
import org.junit.jupiter.api.Assertions;
5151
import org.junit.jupiter.api.BeforeEach;
5252
import org.junit.jupiter.api.Test;
5353

@@ -200,7 +200,7 @@ void testDbcp367() throws Exception {
200200

201201
for (int i = 0; i < threads.length; i++) {
202202
threads[i].join();
203-
Assertions.assertFalse(threads[i].isFailed(), "Thread " + i + " has failed");
203+
assertFalse(threads[i].isFailed(), "Thread " + i + " has failed");
204204
}
205205
}
206206
}

src/test/java/org/apache/commons/dbcp2/managed/TestConnectionWithNarayana.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ Licensed to the Apache Software Foundation (ASF) under one or more
3333

3434
import org.apache.commons.dbcp2.Utils;
3535
import org.junit.jupiter.api.AfterEach;
36-
import org.junit.jupiter.api.Assertions;
3736
import org.junit.jupiter.api.BeforeEach;
3837
import org.junit.jupiter.api.Test;
3938

@@ -177,7 +176,7 @@ void testConnectionInTimeout() throws Exception {
177176
conn.close();
178177
}
179178
}
180-
Assertions.assertEquals(0, mds.getNumActive());
179+
assertEquals(0, mds.getNumActive());
181180
}
182181
}
183182

@@ -198,6 +197,6 @@ void testRepeatedGetConnectionInTimeout() throws Exception {
198197
} finally {
199198
mds.getTransactionManager().rollback();
200199
}
201-
Assertions.assertEquals(0, mds.getNumActive());
200+
assertEquals(0, mds.getNumActive());
202201
}
203202
}

0 commit comments

Comments
 (0)