Change test to be compatible with maven2 surefire; when using surefire, junit is not loaded
via the system classpath. git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/logging/trunk@427396 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
@@ -20,6 +20,8 @@ import java.net.URL;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import junit.framework.Test;
|
import junit.framework.Test;
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
@@ -88,6 +90,21 @@ public class ChildFirstTestCase extends TestCase {
|
|||||||
return new PathableTestSuite(testClass, context);
|
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
|
* Test that the classloader hierarchy is as expected, and that
|
||||||
* calling loadClass() on various classloaders works as expected.
|
* calling loadClass() on various classloaders works as expected.
|
||||||
@@ -133,11 +150,13 @@ public class ChildFirstTestCase extends TestCase {
|
|||||||
PathableClassLoader.class.getName().equals(
|
PathableClassLoader.class.getName().equals(
|
||||||
systemLoader.getClass().getName()));
|
systemLoader.getClass().getName()));
|
||||||
|
|
||||||
// junit classes should be visible; their classloader is system.
|
// junit classes should be visible; their classloader is not
|
||||||
// this will of course throw an exception if not found.
|
// 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");
|
Class junitTest = contextLoader.loadClass("junit.framework.Test");
|
||||||
assertSame("Junit not loaded via systemloader",
|
Set ancestorCLs = getAncestorCLs();
|
||||||
systemLoader, junitTest.getClassLoader());
|
assertFalse("Junit not loaded by ancestor classloader",
|
||||||
|
ancestorCLs.contains(junitTest.getClassLoader()));
|
||||||
|
|
||||||
// jcl api classes should be visible only via the parent
|
// jcl api classes should be visible only via the parent
|
||||||
Class logClass = contextLoader.loadClass("org.apache.commons.logging.Log");
|
Class logClass = contextLoader.loadClass("org.apache.commons.logging.Log");
|
||||||
|
|||||||
Reference in New Issue
Block a user