db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r1332967 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit: BaseJDBCTestCase.java JDBCPerfTestCase.java
Date Wed, 02 May 2012 09:34:59 GMT
Author: kahatlen
Date: Wed May  2 09:34:59 2012
New Revision: 1332967

URL: http://svn.apache.org/viewvc?rev=1332967&view=rev
Log:
DERBY-5726: Make it more difficult to forget calling super.tearDown() from BaseJDBCTestCase's
subclasses

Raise assert failure if test case has not called super.tearDown() after successful completion.

Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBCPerfTestCase.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java?rev=1332967&r1=1332966&r2=1332967&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java Wed
May  2 09:34:59 2012
@@ -401,6 +401,50 @@ public abstract class BaseJDBCTestCase
     {
         getConnection().rollback();
     } 
+
+    /**
+     * <p>
+     * Run the bare test, including {@code setUp()} and {@code tearDown()}.
+     * </p>
+     *
+     * <p>
+     * Subclasses that want to override {@code runBare()}, should override
+     * this method instead. Overriding this method shouldn't be necessary
+     * except in very special cases. Override {@code setUp()} and
+     * {@code tearDown()} instead if possible.
+     * </p>
+     *
+     * <p>
+     * The overridden method would typically want to call
+     * {@code super.runBareOverridable()} to actually run the test.
+     * </p>
+     */
+    protected void runBareOverridable() throws Throwable {
+        super.runBare();
+    }
+
+    /**
+     * <p>
+     * Run the bare test, including {@code setUp()} and {@code tearDown()},
+     * and finally verify that the cached connection has been released.
+     * </p>
+     *
+     * <p>
+     * This method is final to prevent subclasses from accidentally bypassing
+     * the assert that checks if the cached connection has been released.
+     * Subclasses that want to override the method, should override
+     * {@link #runBareOverridable()} instead.
+     * </p>
+     */
+    public final void runBare() throws Throwable {
+        runBareOverridable();
+        // It's quite common to forget to call super.tearDown() when
+        // overriding tearDown() in sub-classes.
+        assertNull(
+            "Connection should be null by now. " +
+            "Missing call to super.tearDown()?", conn);
+    }
+
     /**
      * Tear down this fixture, sub-classes should call
      * super.tearDown(). This cleanups & closes the connection

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBCPerfTestCase.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBCPerfTestCase.java?rev=1332967&r1=1332966&r2=1332967&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBCPerfTestCase.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBCPerfTestCase.java Wed
May  2 09:34:59 2012
@@ -142,12 +142,12 @@ public class JDBCPerfTestCase extends Ba
      * first testrun results and print the average elapsed time 
      * for the remaining runs.  
      */
-    public void runBare() throws Throwable
+    protected void runBareOverridable() throws Throwable
     {
         for (int i = 0; i < repeats; i++)
         {
             println("Repeat ="+i);
-            super.runBare();
+            super.runBareOverridable();
             testRunNum++;
         }
         



Mime
View raw message