@Test public void newJdkProxy() throws Exception { WikipediaServiceJapiMock target = new WikipediaServiceJapiMock(); WikipediaServiceJapi wikipediaServiceJapi = StopWatchProxy.newJdkProxy(target); String article = wikipediaServiceJapi.getArticle("42"); assertThat(article, startsWith("{{Dieser Artikel|behandelt das Jahr 42")); assertThat(wikipediaServiceJapi, not(instanceOf(target.getClass()))); }
public static <T> T newJdkProxy(Object obj) { Class<?> clazz = obj.getClass(); List<Class<?>> interfaces = ClassUtils.getAllInterfaces(clazz); Object res = Proxy.newProxyInstance( clazz.getClassLoader(), interfaces.toArray(new Class[interfaces.size()]), new StopWatchProxy(obj)); return (T) res; }
StopWatchProxy extends DefaultProxyBehavior { public static <T> T newJdkProxy(Object obj) { Class<?> clazz = obj.getClass(); List<Class<?>> interfaces = ClassUtils.getAllInterfaces(clazz); Object res = Proxy.newProxyInstance( clazz.getClassLoader(), interfaces.toArray(new Class[interfaces.size()]), new StopWatchProxy(obj)); return (T) res; } }
StopWatchProxy extends DefaultProxyBehavior { public static <T> T newJdkProxy(Object obj) { Class<?> clazz = obj.getClass(); List<Class<?>> interfaces = ClassUtils.getAllInterfaces(clazz); Object res = Proxy.newProxyInstance( clazz.getClassLoader(), interfaces.toArray(new Class[interfaces.size()]), new StopWatchProxy(obj)); return (T) res; } private  StopWatchProxy(Object obj); }
StopWatchProxy extends DefaultProxyBehavior { public static <T> T newJdkProxy(Object obj) { Class<?> clazz = obj.getClass(); List<Class<?>> interfaces = ClassUtils.getAllInterfaces(clazz); Object res = Proxy.newProxyInstance( clazz.getClassLoader(), interfaces.toArray(new Class[interfaces.size()]), new StopWatchProxy(obj)); return (T) res; } private  StopWatchProxy(Object obj); static T newJdkProxy(Object obj); }
StopWatchProxy extends DefaultProxyBehavior { public static <T> T newJdkProxy(Object obj) { Class<?> clazz = obj.getClass(); List<Class<?>> interfaces = ClassUtils.getAllInterfaces(clazz); Object res = Proxy.newProxyInstance( clazz.getClassLoader(), interfaces.toArray(new Class[interfaces.size()]), new StopWatchProxy(obj)); return (T) res; } private  StopWatchProxy(Object obj); static T newJdkProxy(Object obj);  }