commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From skitch...@apache.org
Subject svn commit: r427396 - /jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/pathable/ChildFirstTestCase.java
Date Tue, 01 Aug 2006 01:16:02 GMT
Author: skitching
Date: Mon Jul 31 18:16:02 2006
New Revision: 427396

URL: http://svn.apache.org/viewvc?rev=427396&view=rev
Log:
Change test to be compatible with maven2 surefire; when using surefire, junit is not loaded
via the system classpath. 

Modified:
    jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/pathable/ChildFirstTestCase.java

Modified: jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/pathable/ChildFirstTestCase.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/pathable/ChildFirstTestCase.java?rev=427396&r1=427395&r2=427396&view=diff
==============================================================================
--- jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/pathable/ChildFirstTestCase.java
(original)
+++ jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/pathable/ChildFirstTestCase.java
Mon Jul 31 18:16:02 2006
@@ -20,6 +20,8 @@
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.Set;
 
 import junit.framework.Test;
 import junit.framework.TestCase;
@@ -87,7 +89,22 @@
         // and return our custom TestSuite class
         return new PathableTestSuite(testClass, context);
     }
-    
+
+    /**
+     * Utility method to return the set of all classloaders in the
+     * parent chain starting from the one that loaded the class for
+     * this object instance.
+     */
+    private Set getAncestorCLs() {
+        Set s = new HashSet();
+        ClassLoader cl = this.getClass().getClassLoader();
+        while (cl != null) {
+            s.add(cl);
+            cl = cl.getParent();
+        }
+        return s;
+    }
+
     /**
      * Test that the classloader hierarchy is as expected, and that
      * calling loadClass() on various classloaders works as expected.
@@ -133,11 +150,13 @@
                 PathableClassLoader.class.getName().equals(
                         systemLoader.getClass().getName()));
 
-        // junit classes should be visible; their classloader is system.
-        // this will of course throw an exception if not found.
+        // junit classes should be visible; their classloader is not
+        // in the hierarchy of parent classloaders for this class,
+        // though it is accessable due to trickery in the PathableClassLoader.
         Class junitTest = contextLoader.loadClass("junit.framework.Test");
-        assertSame("Junit not loaded via systemloader",
-                systemLoader, junitTest.getClassLoader());
+        Set ancestorCLs = getAncestorCLs();
+        assertFalse("Junit not loaded by ancestor classloader", 
+                ancestorCLs.contains(junitTest.getClassLoader()));
 
         // jcl api classes should be visible only via the parent
         Class logClass = contextLoader.loadClass("org.apache.commons.logging.Log");



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message