You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2024/12/14 14:08:02 UTC

(commons-dbcp) 13/19: Use JUnit 5's assertThrows() and friends

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-dbcp.git

commit 206bb01bb66ba702fa0964a9db8950215b2ad3b1
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Sat Dec 14 09:01:54 2024 -0500

    Use JUnit 5's assertThrows() and friends
---
 .../dbcp2/TestDriverManagerConnectionFactory.java  | 82 +++++++++++-----------
 1 file changed, 41 insertions(+), 41 deletions(-)

diff --git a/src/test/java/org/apache/commons/dbcp2/TestDriverManagerConnectionFactory.java b/src/test/java/org/apache/commons/dbcp2/TestDriverManagerConnectionFactory.java
index ce6b368c..d94065a1 100644
--- a/src/test/java/org/apache/commons/dbcp2/TestDriverManagerConnectionFactory.java
+++ b/src/test/java/org/apache/commons/dbcp2/TestDriverManagerConnectionFactory.java
@@ -81,47 +81,47 @@ public class TestDriverManagerConnectionFactory extends AbstractDriverTest {
         cf.createConnection();
     }
 
-    public void testDriverManagerInit(final boolean withProperties) throws Exception {
-        final GenericObjectPoolConfig<PoolableConnection> config = new GenericObjectPoolConfig<>();
-        config.setMaxTotal(10);
-        config.setMaxIdle(0);
-        final Properties properties = new Properties();
-        // The names "user" and "password" are specified in java.sql.DriverManager.getConnection(String, String, String)
-        properties.setProperty(Constants.KEY_USER, "foo");
-        properties.setProperty(Constants.KEY_PASSWORD, "bar");
-        final ConnectionFactory connectionFactory = withProperties ?
-                new DriverManagerConnectionFactory("jdbc:apache:commons:testdriver", properties) :
-                new DriverManagerConnectionFactory("jdbc:apache:commons:testdriver", "foo", "bar");
-        final PoolableConnectionFactory poolableConnectionFactory =
-            new PoolableConnectionFactory(connectionFactory, null);
-        poolableConnectionFactory.setDefaultReadOnly(Boolean.FALSE);
-        poolableConnectionFactory.setDefaultAutoCommit(Boolean.TRUE);
-
-        final GenericObjectPool<PoolableConnection> connectionPool =
-                new GenericObjectPool<>(poolableConnectionFactory, config);
-        poolableConnectionFactory.setPool(connectionPool);
-        final PoolingDataSource<PoolableConnection> dataSource =
-                new PoolingDataSource<>(connectionPool);
-
-        final ConnectionThread[] connectionThreads = new ConnectionThread[10];
-        final Thread[] threads = new Thread[10];
-
-        for (int i = 0; i < 10; i++) {
-            connectionThreads[i] = new ConnectionThread(dataSource);
-            threads[i] = new Thread(connectionThreads[i]);
-        }
-        for (int i = 0; i < 10; i++) {
-            threads[i].start();
-        }
-        for (int i = 0; i < 10; i++) {
-            while (threads[i].isAlive()){//JDK1.5: getState() != Thread.State.TERMINATED) {
-                Thread.sleep(100);
-            }
-            if (!connectionThreads[i].getResult()) {
-                fail("Exception during getConnection(): " + connectionThreads[i]);
-            }
-        }
-    }
+	public void testDriverManagerInit(final boolean withProperties) throws Exception {
+		final GenericObjectPoolConfig<PoolableConnection> config = new GenericObjectPoolConfig<>();
+		config.setMaxTotal(10);
+		config.setMaxIdle(0);
+		final Properties properties = new Properties();
+		// The names "user" and "password" are specified in
+		// java.sql.DriverManager.getConnection(String, String, String)
+		properties.setProperty(Constants.KEY_USER, "foo");
+		properties.setProperty(Constants.KEY_PASSWORD, "bar");
+		final ConnectionFactory connectionFactory = withProperties
+				? new DriverManagerConnectionFactory("jdbc:apache:commons:testdriver", properties)
+				: new DriverManagerConnectionFactory("jdbc:apache:commons:testdriver", "foo", "bar");
+		final PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory,
+				null);
+		poolableConnectionFactory.setDefaultReadOnly(Boolean.FALSE);
+		poolableConnectionFactory.setDefaultAutoCommit(Boolean.TRUE);
+
+		final GenericObjectPool<PoolableConnection> connectionPool = new GenericObjectPool<>(poolableConnectionFactory,
+				config);
+		poolableConnectionFactory.setPool(connectionPool);
+		final PoolingDataSource<PoolableConnection> dataSource = new PoolingDataSource<>(connectionPool);
+
+		final ConnectionThread[] connectionThreads = new ConnectionThread[10];
+		final Thread[] threads = new Thread[10];
+
+		for (int i = 0; i < 10; i++) {
+			connectionThreads[i] = new ConnectionThread(dataSource);
+			threads[i] = new Thread(connectionThreads[i]);
+		}
+		for (int i = 0; i < 10; i++) {
+			threads[i].start();
+		}
+		for (int i = 0; i < 10; i++) {
+			while (threads[i].isAlive()) { // JDK1.5: getState() != Thread.State.TERMINATED) {
+				Thread.sleep(100);
+			}
+			if (!connectionThreads[i].getResult()) {
+				fail("Exception during getConnection(): " + connectionThreads[i]);
+			}
+		}
+	}
 
     @Test
     public void testDriverManagerInitWithCredentials() throws Exception {