@Test public void shouldInvokeSimpleClassMethod() throws Exception { new InvocationProxy<VersionSupplier>(VersionSupplier.class) { @Override public Object invoke(Method method, Object... args) { methodCalled = method; argsCalled = args; return null; } }.newInstance().getVersion(null); assertEquals("getVersion", methodCalled.getName()); assertEquals(1, argsCalled.length); }
public T newInstance() { String className = targetType.getName() + "$$InvocationProxy"; try { Class<T> type = proxyType(className); log.debug("instantiate {}", type); Constructor<T> constructor = type.getConstructor(InvocationProxy.class); return constructor.newInstance(this); } catch (Exception e) { throw new RuntimeException("can't generate " + className, e); } }
InvocationProxy { public T newInstance() { String className = targetType.getName() + "$$InvocationProxy"; try { Class<T> type = proxyType(className); log.debug("instantiate {}", type); Constructor<T> constructor = type.getConstructor(InvocationProxy.class); return constructor.newInstance(this); } catch (Exception e) { throw new RuntimeException("can't generate " + className, e); } } }
InvocationProxy { public T newInstance() { String className = targetType.getName() + "$$InvocationProxy"; try { Class<T> type = proxyType(className); log.debug("instantiate {}", type); Constructor<T> constructor = type.getConstructor(InvocationProxy.class); return constructor.newInstance(this); } catch (Exception e) { throw new RuntimeException("can't generate " + className, e); } } InvocationProxy(Class<T> targetType); }
InvocationProxy { public T newInstance() { String className = targetType.getName() + "$$InvocationProxy"; try { Class<T> type = proxyType(className); log.debug("instantiate {}", type); Constructor<T> constructor = type.getConstructor(InvocationProxy.class); return constructor.newInstance(this); } catch (Exception e) { throw new RuntimeException("can't generate " + className, e); } } InvocationProxy(Class<T> targetType); T newInstance(); abstract Object invoke(Method method, Object... args); }
InvocationProxy { public T newInstance() { String className = targetType.getName() + "$$InvocationProxy"; try { Class<T> type = proxyType(className); log.debug("instantiate {}", type); Constructor<T> constructor = type.getConstructor(InvocationProxy.class); return constructor.newInstance(this); } catch (Exception e) { throw new RuntimeException("can't generate " + className, e); } } InvocationProxy(Class<T> targetType); T newInstance(); abstract Object invoke(Method method, Object... args);  }