Examples of CustomPrintStream


Examples of org.jboss.forge.classloader.mock.CustomPrintStream

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

      Class<?> foreignType = dep1Loader.loadClass(CustomPrintStreamFactory.class.getName());
      try
      {
         @SuppressWarnings({ "unused" })
         CustomPrintStream custom = (CustomPrintStream) foreignType.getMethod("getPrintStream")
                  .invoke(foreignType.newInstance());

         Assert.fail("Should have received a classcast exception");
      }
      catch (ClassCastException e)
      {
      }

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

      Assert.assertTrue(Proxies.isForgeProxy(enhancedFactory));
      PrintStream result = enhancedFactory.getPrintStream();
      Assert.assertFalse(Proxies.isForgeProxy(result));

      File file = File.createTempFile("furnace", "printStream");
      file.deleteOnExit();
      enhancedFactory.usePrintStream(new CustomPrintStream(file));

      try
      {
         @SuppressWarnings("unused")
         CustomPrintStream customResult = enhancedFactory.getCustomPrintStream();
         Assert.fail("Should have received a classcast exception");
      }
      catch (ClassCastException e)
      {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.