}
final URLClassLoader cl1 = createClassLoader( "cl1.jar" );
final URLClassLoader cl2 = createClassLoader( "cl2.jar" );
final ClassLoader[] cls = new ClassLoader[]{cl1, cl2};
final JoinClassLoader join =
new JoinClassLoader( cls, ClassLoader.getSystemClassLoader() );
try
{
join.loadClass( DataConstants.DATA1_CLASS );
}
catch( ClassNotFoundException e )
{
fail( "Unable to load Data1 from cl1 classloader" );
}
try
{
join.loadClass( DataConstants.DATA2_CLASS );
}
catch( ClassNotFoundException e )
{
fail( "Unable to load CL2Data from cl2 classloader" );
}
try
{
join.loadClass( "i.no.exist" );
fail( "Expected that would be unable to load non-existent class" );
}
catch( ClassNotFoundException e )
{
}
try
{
assertEquals( "Loading from system classloader",
Integer.class,
join.loadClass( Integer.class.getName() ) );
}
catch( ClassNotFoundException e )
{
fail( "Unable to load Integer from classloader" );
}
final URL url1 = join.getResource( DataConstants.DATA1_RESOURCE );
assertNotNull( "Loading " + DataConstants.DATA1_RESOURCE + " from c1 classloader",
url1 );
final URL url2 = join.getResource( "noexist.txt" );
assertNull( "Loading noexist.txt from c1 classloader", url2 );
final Enumeration resources1 = join.getResources( DataConstants.DATA1_RESOURCE );
assertNotNull( "Loading set of " + DataConstants.DATA1_RESOURCE + " from c1 classloader",
resources1 );
assertTrue( "Count of resource from classloader", resources1.hasMoreElements() );
assertEquals( "Resource found from classloader", url1, resources1.nextElement() );
assertTrue( "Second Count of resource from classloader", !resources1.hasMoreElements() );
final Enumeration resources2 = join.getResources( "noexist.txt" );
assertNotNull( "Loading set of noexist.txt from c1 classloader", resources2 );
assertTrue( "Count of noexist.txt from classloader", !resources2.hasMoreElements() );
try
{