commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r895743 - /commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp/TestPoolableConnection.java
Date Mon, 04 Jan 2010 18:47:03 GMT
Author: sebb
Date: Mon Jan  4 18:47:01 2010
New Revision: 895743

URL: http://svn.apache.org/viewvc?rev=895743&view=rev
Log:
No point in catching/reporting Exceptions that JUnit handles
Catch SQLException rather than generic Exception

Modified:
    commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp/TestPoolableConnection.java

Modified: commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp/TestPoolableConnection.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp/TestPoolableConnection.java?rev=895743&r1=895742&r2=895743&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp/TestPoolableConnection.java
(original)
+++ commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp/TestPoolableConnection.java
Mon Jan  4 18:47:01 2010
@@ -51,51 +51,37 @@
         pool.setFactory(factory);
     }
 
-    public void testConnectionPool() {
+    public void testConnectionPool() throws Exception {
         // Grab a new connection from the pool
-        Connection c = null;
-        try {
-            c = (Connection)pool.borrowObject();
-        } catch (Exception e) {
-            fail("Could not fetch Connection from pool: " + e.getMessage());
-        }
+        Connection c = (Connection)pool.borrowObject();
 
         assertNotNull("Connection should be created and should not be null", c);
         assertEquals("There should be exactly one active object in the pool", 1, pool.getNumActive());
 
         // Now return the connection by closing it
-        try {
-            c.close(); // Can't be null
-        } catch (SQLException e) {
-            fail("Could not close connection: " + e.getMessage());
-        }
+        c.close(); // Can't be null
 
         assertEquals("There should now be zero active objects in the pool", 0, pool.getNumActive());
     }
 
     // Bugzilla Bug 33591: PoolableConnection leaks connections if the
     // delegated connection closes itself.
-    public void testPoolableConnectionLeak() {
-        Connection conn = null;
-        try {
-            // 'Borrow' a connection from the pool
-            conn = (Connection)pool.borrowObject();
-
-            // Now close our innermost delegate, simulating the case where the
-            // underlying connection closes itself
-            ((PoolableConnection)conn).getInnermostDelegate().close();
-            
-            // At this point, we can close the pooled connection. The
-            // PoolableConnection *should* realise that its underlying
-            // connection is gone and invalidate itself. The pool should have no
-            // active connections.
-        } catch (Exception e) {
-            fail("Exception occured while testing connection leak: " + e.getMessage());
-        }
+    public void testPoolableConnectionLeak() throws Exception {
+        // 'Borrow' a connection from the pool
+        Connection conn = (Connection)pool.borrowObject();
+
+        // Now close our innermost delegate, simulating the case where the
+        // underlying connection closes itself
+        ((PoolableConnection)conn).getInnermostDelegate().close();
+        
+        // At this point, we can close the pooled connection. The
+        // PoolableConnection *should* realise that its underlying
+        // connection is gone and invalidate itself. The pool should have no
+        // active connections.
 
         try {
             conn.close();
-        } catch (Exception e) {
+        } catch (SQLException e) {
             // Here we expect 'connection already closed', but the connection
             // should *NOT* be returned to the pool
         }



Mime
View raw message