Package org.jboss.forge.classloader.mock.result

Examples of org.jboss.forge.classloader.mock.result.Implementation


      ClassLoader dep1Loader = registry.getAddon(AddonId.from("dep", "1")).getClassLoader();

      Class<?> foreignType = dep1Loader.loadClass(InstanceFactoryImpl.class.getName());
      try
      {
         Implementation local = (Implementation) foreignType.getMethod("getInstance")
                  .invoke(foreignType.newInstance());

         Assert.fail("Should have received a " + ClassCastException.class.getName() + " but got a real object ["
                  + local + "]");
      }
      catch (ClassCastException e)
      {
      }
      catch (Exception e)
      {
         Assert.fail("Should have received a " + ClassCastException.class.getName() + " but was: " + e);
      }

      Object delegate = foreignType.newInstance();
      InstanceFactoryImpl enhancedFactory = (InstanceFactoryImpl) ClassLoaderAdapterBuilder.callingLoader(thisLoader)
               .delegateLoader(dep1Loader).enhance(delegate);

      Assert.assertTrue(Proxies.isForgeProxy(enhancedFactory));
      Implementation enhancedInstance = enhancedFactory.getInstance();

      Class<?> unwrappedType = Proxies.unwrapProxyTypes(enhancedInstance.getClass(), dep1Loader);
      Assert.assertEquals(ClassLoaders.loadClass(dep1Loader, Implementation.class.getName()), unwrappedType);
   }
View Full Code Here


      ClassLoader dep1Loader = registry.getAddon(AddonId.from("dep", "1")).getClassLoader();

      Class<?> foreignType = dep1Loader.loadClass(InstanceFactoryImpl.class.getName());
      try
      {
         Implementation local = (Implementation) foreignType.getMethod("getInstance")
                  .invoke(foreignType.newInstance());

         Assert.fail("Should have received a " + ClassCastException.class.getName() + " but got a real object ["
                  + local + "]");
      }
      catch (ClassCastException e)
      {
      }
      catch (Exception e)
      {
         Assert.fail("Should have received a " + ClassCastException.class.getName() + " but was: " + e);
      }

      Object delegate = foreignType.newInstance();
      InstanceFactoryImpl enhancedFactory = (InstanceFactoryImpl) ClassLoaderAdapterBuilder.callingLoader(thisLoader)
               .delegateLoader(dep1Loader).enhance(delegate);

      Assert.assertTrue(Proxies.isForgeProxy(enhancedFactory));
      Implementation enhancedInstance = enhancedFactory.getInstance();
      Assert.assertTrue(Proxies.isForgeProxy(enhancedInstance));
   }
View Full Code Here

TOP

Related Classes of org.jboss.forge.classloader.mock.result.Implementation

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.