@Test
  public void testParameterPassthroughIfTypeIsShared() throws Exception {
    AddonRegistry registry =
        LocalServices.getFurnace(getClass().getClassLoader()).getAddonRegistry();
    ClassLoader thisLoader = ClassLoaderAdapterPassthroughTest.class.getClassLoader();
    ClassLoader loader1 = registry.getAddon(AddonId.from("dep", "1")).getClassLoader();

    ClassWithGetterAndSetter local = new ClassWithGetterAndSetter();
    local.setPassthrough(
        (ClassWithPassthroughMethod)
            loader1.loadClass(ClassWithPassthroughMethod.class.getName()).newInstance());

    Object delegate = loader1.loadClass(ClassWithGetterAndSetter.class.getName()).newInstance();
    ClassWithGetterAndSetter enhanced =
        (ClassWithGetterAndSetter)
            ClassLoaderAdapterBuilder.callingLoader(thisLoader)
                .delegateLoader(loader1)
                .enhance(delegate);

    enhanced.setPassthrough(new ClassWithPassthroughMethod());

    Assert.assertNotNull(enhanced);
    Assert.assertNotNull(enhanced.getPassthrough());
    Assert.assertFalse(Proxies.isForgeProxy(enhanced.getPassthrough()));
    Assert.assertFalse(enhanced.assertPassthroughNotProxied());
  }
  @Test
  public void testSharedImplementationTypeIncludedInProxy() throws Exception {
    AddonRegistry registry =
        LocalServices.getFurnace(getClass().getClassLoader()).getAddonRegistry();
    ClassLoader thisLoader = ClassLoaderAdapterExceptionProxyTest.class.getClassLoader();
    ClassLoader dep1Loader = registry.getAddon(AddonId.from("dep", "1")).getClassLoader();

    Class<?> foreignType = dep1Loader.loadClass(ExceptionFactory.class.getName());
    try {
      ExceptionFactory factory = (ExceptionFactory) foreignType.newInstance();

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

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

    Assert.assertTrue(Proxies.isForgeProxy(enhancedFactory));

    String message = "AbstractA message.";
    try {
      enhancedFactory.throwException(message);
    } catch (MockException e) {
      Assert.assertTrue(Proxies.isForgeProxy(e));
      Assert.assertEquals(message, e.getMessage());
    } catch (Exception e) {
      Assert.fail("Exception was not of a compatible type.");
    }
  }