}
}
public void testDynamicImport()
{
Importer importer = new DefaultImporter( );
importer.addImport( new DefaultImportEntry( "java.util.*" ) );
ClassLoader cl = getClass( ).getClassLoader( );
/* dynamic import, should work */
try
{
Class clazz = importer.importClass( cl,
"HashMap" );
assertSame( java.util.HashMap.class,
clazz );
}
catch ( ClassNotFoundException e )
{
fail( e.getMessage( ) );
}
catch ( Error e )
{
fail( e.getMessage( ) );
}
/* dynamic import, should throw ClassNotFoundException */
try
{
Class clazz = importer.importClass( cl,
"NoneExistingClass" );
fail( "Class NoneExistingClass should not be found" );
}
catch ( ClassNotFoundException e )
{
// correct exception, so pass
}
catch ( Error e )
{
fail( "Incorrect Error exception, should have been ClassNotFound" );
}
/* dynamic import, should fail and throw Error */
importer.addImport( new DefaultImportEntry( "java.awt.*" ) );
try
{
Class clazz = importer.importClass( cl,
"List" );
fail( "Should fail as imports are ambiguous for List" );
}
catch ( ClassNotFoundException e )
{
fail( "Incorrect ClassNotFoundException exception, should have been Error" );
}
catch ( Error e )
{
// correct exception, so pass
}
/* recheck that HashMap still works */
try
{
Class clazz = importer.importClass( cl,
"HashMap" );
assertSame( java.util.HashMap.class,
clazz );
}
catch ( ClassNotFoundException e )