// Determine the URL to this .class file, so that we can then
// append the priority dirs to it. For tidiness, load this
// class through a dummy loader though this is not absolutely
// necessary...
PathableClassLoader dummy = new PathableClassLoader(null);
dummy.useSystemLoader("junit.");
dummy.addLogicalLib("testclasses");
dummy.addLogicalLib("commons-logging");
String thisClassPath = thisClass.getName().replace('.', '/') + ".class";
URL baseUrl = dummy.findResource(thisClassPath);
// Now set up the desired classloader hierarchy. Everything goes into
// the parent classpath, but we exclude the custom LogFactoryImpl
// class.
//
// We then create a tccl classloader that can see the custom
// LogFactory class. Therefore if that class can be found, then the
// TCCL must have been used to load it.
PathableClassLoader emptyLoader = new PathableClassLoader(null);
PathableClassLoader parentLoader = new PathableClassLoader(null);
parentLoader.useSystemLoader("junit.");
parentLoader.addLogicalLib("commons-logging");
parentLoader.addLogicalLib("testclasses");
// hack to ensure that the testcase classloader can't see
// the custom MyLogFactoryImpl
parentLoader.useExplicitLoader(
MY_LOG_FACTORY_PKG + ".", emptyLoader);
URL propsEnableUrl = new URL(baseUrl, "props_disable_tccl/");
parentLoader.addURL(propsEnableUrl);
PathableClassLoader tcclLoader = new PathableClassLoader(parentLoader);
tcclLoader.addLogicalLib("testclasses");
Class testClass = parentLoader.loadClass(thisClass.getName());
return new PathableTestSuite(testClass, tcclLoader);
}