IsolatedLauncherProxy implements InvocationHandler { public static <T> T create(ClassLoader cl, Class<T> interfaceClass, String proxiedClassName, Logger logger) throws ReflectiveOperationException { Object proxied = createProxiedObject(cl, proxiedClassName); Class<?> loadedInterfaceClass = cl.loadClass(interfaceClass.getName()); return (T) create(cl, proxied, loadedInterfaceClass, logger); } private  IsolatedLauncherProxy(ClassLoader cl, Object proxied, Logger logger); static T create(ClassLoader cl, Class<T> interfaceClass, String proxiedClassName, Logger logger); static T create(ClassLoader cl, Object proxied, Class<T> interfaceClass, Logger logger); @Override Object invoke(Object proxy, Method method, Object[] args);  }
@Test public void delegate_proxied() throws ClassNotFoundException, InstantiationException, IllegalAccessException { String str = "test"; CharSequence s = IsolatedLauncherProxy.create(cl, str, CharSequence.class, mock(Logger.class)); assertThat(s).isEqualTo(str); }
@Test(expected = IllegalStateException.class) public void exceptions_unwrapped() throws ReflectiveOperationException { Runnable r = IsolatedLauncherProxy.create(cl, Runnable.class, ExceptionThrower.class.getName(), mock(Logger.class)); r.run(); }
@Test public void create_proxied() throws Exception { Callable<?> c = IsolatedLauncherProxy.create(cl, Callable.class, SimpleClass.class.getName(), mock(Logger.class)); assertThat(c.getClass().getClassLoader()).isEqualTo(cl); assertThat(c.getClass().getClassLoader()).isNotEqualTo(Thread.currentThread().getContextClassLoader()); assertThat(c.call()).isEqualTo(URLClassLoader.class.getSimpleName()); }