commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From joe...@apache.org
Subject svn commit: r1452354 - /commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/test/AbstractTestSuite.java
Date Mon, 04 Mar 2013 15:53:37 GMT
Author: joehni
Date: Mon Mar  4 15:53:37 2013
New Revision: 1452354

URL: http://svn.apache.org/r1452354
Log:
Evaluate thread snapshot after tearDown. Do not wipe fTest, it results in a NPE for any filing
assertion later.

Modified:
    commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/test/AbstractTestSuite.java

Modified: commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/test/AbstractTestSuite.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/test/AbstractTestSuite.java?rev=1452354&r1=1452353&r2=1452354&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/test/AbstractTestSuite.java
(original)
+++ commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/test/AbstractTestSuite.java
Mon Mar  4 15:53:37 2013
@@ -24,6 +24,9 @@ import java.util.ArrayList;
 import java.util.Enumeration;
 import java.util.List;
 
+import junit.framework.Protectable;
+import junit.framework.TestResult;
+
 import junit.extensions.TestSetup;
 import junit.framework.Test;
 import junit.framework.TestSuite;
@@ -137,6 +140,20 @@ public abstract class AbstractTestSuite
     }
 
     @Override
+    public void run(final TestResult result) {
+        Protectable p = new Protectable() {
+            @Override
+            public void protect() throws Exception {
+                setUp();
+                basicRun(result);
+                tearDown();
+                validateThreadSnapshot();
+            }
+        };
+        result.runProtected(this, p);
+    }
+
+    @Override
     protected void setUp() throws Exception
     {
         startThreadSnapshot = createThreadSnapshot();
@@ -195,7 +212,6 @@ public abstract class AbstractTestSuite
         writeFolder = null;
         baseFolder = null;
         testSuite = null;
-        fTest = null;
 
         // force the SoftRefFilesChache to free all files
         System.gc();
@@ -208,8 +224,16 @@ public abstract class AbstractTestSuite
         Thread.sleep(1000);
 
         manager.freeUnusedResources();
-        endThreadSnapshot = createThreadSnapshot();
+        manager.close();
 
+        // Make sure temp directory is empty or gone
+        checkTempDir("Temp dir not empty after test");
+    }
+
+    private void validateThreadSnapshot()
+    {
+        endThreadSnapshot = createThreadSnapshot();
+    
         final Thread[] diffThreadSnapshot = diffThreadSnapshot(startThreadSnapshot, endThreadSnapshot);
         if (diffThreadSnapshot.length > 0)
         {
@@ -229,11 +253,6 @@ public abstract class AbstractTestSuite
             // }
         }
         // System.in.read();
-
-        manager.close();
-
-        // Make sure temp directory is empty or gone
-        checkTempDir("Temp dir not empty after test");
     }
 
     /**
@@ -266,7 +285,7 @@ public abstract class AbstractTestSuite
         for (int iter = 0; iter < threadSnapshot.length; iter++)
         {
             final Thread thread = threadSnapshot[iter];
-            if (thread == null)
+            if (thread == null || !thread.isAlive())
             {
                 continue;
             }
@@ -274,10 +293,13 @@ public abstract class AbstractTestSuite
             sb.append("#");
             sb.append(iter + 1);
             sb.append(": ");
-            sb.append(thread.getThreadGroup().getName());
+            sb.append(thread.getThreadGroup() != null ? 
+                thread.getThreadGroup().getName() : "(null)");
             sb.append("\t");
             sb.append(thread.getName());
             sb.append("\t");
+            sb.append(thread.getState());
+            sb.append("\t");
             if (thread.isDaemon())
             {
                 sb.append("daemon");



Mime
View raw message