AddonRegistry registry = LocalServices.getFurnace(getClass().getClassLoader())
.getAddonRegistry();
ClassLoader thisLoader = ClassLoaderAdapterCollisionsTest.class.getClassLoader();
ClassLoader dep1Loader = registry.getAddon(AddonId.from("dep1", "1")).getClassLoader();
ClassWithGetterAndSetter enhanced;
try
{
enhanced = (ClassWithGetterAndSetter) dep1Loader.loadClass(
ClassWithGetterAndSetter.class.getName()).newInstance();
Assert.fail("Should have received a " + ClassCastException.class.getName());
}
catch (ClassCastException e)
{
}
catch (Exception e)
{
Assert.fail("Should have received a " + ClassCastException.class.getName());
}
Object delegate = dep1Loader.loadClass(ClassWithGetterAndSetter.class.getName()).newInstance();
enhanced = (ClassWithGetterAndSetter) ClassLoaderAdapterBuilder.callingLoader(thisLoader)
.delegateLoader(dep1Loader).enhance(delegate);
Assert.assertFalse(Proxies.isForgeProxy(delegate));
Assert.assertFalse(Proxies.isProxyType(delegate.getClass()));
Assert.assertTrue(Proxies.isForgeProxy(enhanced));
Assert.assertTrue(Proxies.isProxyType(enhanced.getClass()));
Assert.assertNotNull(enhanced);
Assert.assertNull(enhanced.getPassthrough());
}