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/08/03 11:41:42 UTC
(commons-dbcp) branch master updated (ffe8d43d -> 5a2f7346)
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-dbcp.git
from ffe8d43d Bump org.hamcrest:hamcrest from 2.2 to 3.0 #410
new 49fa99ae Use assertThrows()
new a03b8588 Use assertThrows()
new 5a2f7346 Use try-with-resources
The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../dbcp2/cpdsadapter/TestDriverAdapterCPDS.java | 27 +++++---------------
.../datasources/TestPerUserPoolDataSource.java | 29 ++++++++++------------
2 files changed, 19 insertions(+), 37 deletions(-)
(commons-dbcp) 01/03: Use assertThrows()
Posted by gg...@apache.org.
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 49fa99ae08766e3e332963f408b7a361cc541765
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Aug 3 07:38:23 2024 -0400
Use assertThrows()
---
.../dbcp2/cpdsadapter/TestDriverAdapterCPDS.java | 27 +++++-----------------
1 file changed, 6 insertions(+), 21 deletions(-)
diff --git a/src/test/java/org/apache/commons/dbcp2/cpdsadapter/TestDriverAdapterCPDS.java b/src/test/java/org/apache/commons/dbcp2/cpdsadapter/TestDriverAdapterCPDS.java
index 6fc6042f..68573f42 100644
--- a/src/test/java/org/apache/commons/dbcp2/cpdsadapter/TestDriverAdapterCPDS.java
+++ b/src/test/java/org/apache/commons/dbcp2/cpdsadapter/TestDriverAdapterCPDS.java
@@ -290,30 +290,15 @@ public class TestDriverAdapterCPDS {
* JIRA: DBCP-245
*/
@Test
- public void testIncorrectPassword() throws Exception
- {
+ public void testIncorrectPassword() throws Exception {
pcds.getPooledConnection("u2", "p2").close();
- try {
- // Use bad password
- pcds.getPooledConnection("u1", "zlsafjk");
- fail("Able to retrieve connection with incorrect password");
- } catch (final SQLException e1) {
- // should fail
-
- }
+ // Use bad password
+ assertThrows(SQLException.class, () -> pcds.getPooledConnection("u1", "zlsafjk"), "Able to retrieve connection with incorrect password");
// Use good password
- pcds.getPooledConnection("u1", "p1").close();
- try {
- pcds.getPooledConnection("u1", "x");
- fail("Able to retrieve connection with incorrect password");
- }
- catch (final SQLException e) {
- if (!e.getMessage().startsWith("x is not the correct password")) {
- throw e;
- }
- // else the exception was expected
- }
+ SQLException e = assertThrows(SQLException.class, () -> pcds.getPooledConnection("u1", "x"), "Able to retrieve connection with incorrect password");
+ assertTrue(e.getMessage().startsWith("x is not the correct password"));
+ // else the exception was expected
// Make sure we can still use our good password.
pcds.getPooledConnection("u1", "p1").close();
(commons-dbcp) 02/03: Use assertThrows()
Posted by gg...@apache.org.
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 a03b858896eee3fb417a2b29db61c04e607c642d
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Aug 3 07:40:30 2024 -0400
Use assertThrows()
Longer lines
---
.../datasources/TestPerUserPoolDataSource.java | 25 ++++++++++------------
1 file changed, 11 insertions(+), 14 deletions(-)
diff --git a/src/test/java/org/apache/commons/dbcp2/datasources/TestPerUserPoolDataSource.java b/src/test/java/org/apache/commons/dbcp2/datasources/TestPerUserPoolDataSource.java
index 529c6beb..9cfc774d 100644
--- a/src/test/java/org/apache/commons/dbcp2/datasources/TestPerUserPoolDataSource.java
+++ b/src/test/java/org/apache/commons/dbcp2/datasources/TestPerUserPoolDataSource.java
@@ -90,7 +90,9 @@ public class TestPerUserPoolDataSource extends TestConnectionPool {
((PerUserPoolDataSource) ds).close();
}
- // See DBCP-8
+ /**
+ * See DBCP-8
+ */
@Test
public void testChangePassword() throws Exception {
assertThrows(SQLException.class, () -> ds.getConnection(user, "bay"));
@@ -99,28 +101,23 @@ public class TestPerUserPoolDataSource extends TestConnectionPool {
final Connection con3 = ds.getConnection(user, "bar");
con1.close();
con2.close();
- TesterDriver.addUser(user,"bay"); // change the user/password setting
+ TesterDriver.addUser(user, "bay"); // change the user/password setting
try {
final Connection con4 = ds.getConnection(user, "bay"); // new password
// Idle instances with old password should have been cleared
- assertEquals(0, ((PerUserPoolDataSource) ds).getNumIdle(user),
- "Should be no idle connections in the pool");
+ assertEquals(0, ((PerUserPoolDataSource) ds).getNumIdle(user), "Should be no idle connections in the pool");
con4.close();
// Should be one idle instance with new pwd
- assertEquals(1, ((PerUserPoolDataSource) ds).getNumIdle(user),
- "Should be one idle connection in the pool");
- try (Connection c = ds.getConnection(user, "bar")) { // old password
- fail("Should have generated SQLException");
- } catch (final SQLException expected) {
- }
+ assertEquals(1, ((PerUserPoolDataSource) ds).getNumIdle(user), "Should be one idle connection in the pool");
+ // old password
+ assertThrows(SQLException.class, () -> ds.getConnection(user, "bar"), "Should have generated SQLException");
final Connection con5 = ds.getConnection(user, "bay"); // take the idle one
con3.close(); // Return a connection with the old password
- ds.getConnection(user, "bay").close(); // will try bad returned connection and destroy it
- assertEquals(1, ((PerUserPoolDataSource) ds).getNumIdle(user),
- "Should be one idle connection in the pool");
+ ds.getConnection(user, "bay").close(); // will try bad returned connection and destroy it
+ assertEquals(1, ((PerUserPoolDataSource) ds).getNumIdle(user), "Should be one idle connection in the pool");
con5.close();
} finally {
- TesterDriver.addUser(user,"bar");
+ TesterDriver.addUser(user, "bar");
}
}
(commons-dbcp) 03/03: Use try-with-resources
Posted by gg...@apache.org.
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 5a2f73466e64e410d314db89e858867af8422108
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Aug 3 07:41:05 2024 -0400
Use try-with-resources
---
.../commons/dbcp2/datasources/TestPerUserPoolDataSource.java | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/src/test/java/org/apache/commons/dbcp2/datasources/TestPerUserPoolDataSource.java b/src/test/java/org/apache/commons/dbcp2/datasources/TestPerUserPoolDataSource.java
index 9cfc774d..d74edc9f 100644
--- a/src/test/java/org/apache/commons/dbcp2/datasources/TestPerUserPoolDataSource.java
+++ b/src/test/java/org/apache/commons/dbcp2/datasources/TestPerUserPoolDataSource.java
@@ -111,11 +111,11 @@ public class TestPerUserPoolDataSource extends TestConnectionPool {
assertEquals(1, ((PerUserPoolDataSource) ds).getNumIdle(user), "Should be one idle connection in the pool");
// old password
assertThrows(SQLException.class, () -> ds.getConnection(user, "bar"), "Should have generated SQLException");
- final Connection con5 = ds.getConnection(user, "bay"); // take the idle one
- con3.close(); // Return a connection with the old password
- ds.getConnection(user, "bay").close(); // will try bad returned connection and destroy it
- assertEquals(1, ((PerUserPoolDataSource) ds).getNumIdle(user), "Should be one idle connection in the pool");
- con5.close();
+ try (Connection con5 = ds.getConnection(user, "bay")) { // take the idle one
+ con3.close(); // Return a connection with the old password
+ ds.getConnection(user, "bay").close(); // will try bad returned connection and destroy it
+ assertEquals(1, ((PerUserPoolDataSource) ds).getNumIdle(user), "Should be one idle connection in the pool");
+ }
} finally {
TesterDriver.addUser(user, "bar");
}