You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by sk...@apache.org on 2005/07/05 10:10:21 UTC

svn commit: r209240 - /jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/pathable/ParentFirstTestCase.java

Author: skitching
Date: Tue Jul  5 01:10:19 2005
New Revision: 209240

URL: http://svn.apache.org/viewcvs?rev=209240&view=rev
Log:
Renamed from PathableTestCase, as it really tests parent-first classloading.

Added:
    jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/pathable/ParentFirstTestCase.java
      - copied, changed from r209198, jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/pathable/PathableTestCase.java

Copied: jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/pathable/ParentFirstTestCase.java (from r209198, jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/pathable/PathableTestCase.java)
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/pathable/ParentFirstTestCase.java?p2=jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/pathable/ParentFirstTestCase.java&p1=jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/pathable/PathableTestCase.java&r1=209198&r2=209240&rev=209240&view=diff
==============================================================================
--- jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/pathable/PathableTestCase.java (original)
+++ jakarta/commons/proper/logging/trunk/src/test/org/apache/commons/logging/pathable/ParentFirstTestCase.java Tue Jul  5 01:10:19 2005
@@ -28,7 +28,8 @@
 import org.apache.commons.logging.PathableClassLoader;
 
 /**
- * Tests for the PathableTestSuite and PathableClassLoader functionality.
+ * Tests for the PathableTestSuite and PathableClassLoader functionality,
+ * where lookup order for the PathableClassLoader is parent-first.
  * <p>
  * These tests assume:
  * <ul>
@@ -37,7 +38,7 @@
  * </ul>
  */
 
-public class PathableTestCase extends TestCase {
+public class ParentFirstTestCase extends TestCase {
     
     /**
      * Set up a custom classloader hierarchy for this test case.
@@ -49,13 +50,19 @@
      * </ul>
      */
     public static Test suite() throws Exception {
-        // make the parent a direct child of the bootloader to hide all
+        Class thisClass = ParentFirstTestCase.class;
+        ClassLoader thisClassLoader = thisClass.getClassLoader();
+
+        // Make the parent a direct child of the bootloader to hide all
         // other classes in the system classpath
         PathableClassLoader parent = new PathableClassLoader(null);
         
-        // make the junit classes from the system classpath visible, though,
-        // as junit won't be able to call this class at all without this..
-        parent.useSystemLoader("junit.");
+        // Make the junit classes visible as a special case, as junit
+        // won't be able to call this class at all without this. The
+        // junit classes must be visible from the classloader that loaded
+        // this class, so use that as the source for future access to classes
+        // from the junit package.
+        parent.useExplicitLoader("junit.", thisClassLoader);
         
         // make the commons-logging.jar classes visible via the parent
         parent.addLogicalLib("commons-logging");
@@ -72,7 +79,7 @@
         PathableClassLoader context = new PathableClassLoader(child);
 
         // reload this class via the child classloader
-        Class testClass = child.loadClass(PathableTestCase.class.getName());
+        Class testClass = child.loadClass(thisClass.getName());
         
         // and return our custom TestSuite class
         return new PathableTestSuite(testClass, context);



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