@Test public void shouldNeverCallSuperclassConstructors() { TheClassWithManyConstructors proxy = proxifier.proxify(TheClassWithManyConstructors.class, new MethodInvocation<TheClassWithManyConstructors>() { public Object intercept(TheClassWithManyConstructors proxy, Method method, Object[] args, SuperMethod superMethod) { return superMethod.invoke(proxy, args); } }); assertThat(proxy.wasNumberConstructorCalled(), is(false)); assertThat(proxy.getNumber(), is(nullValue())); }
public <T> T proxify(Class<T> type, MethodInvocation<? super T> handler) { final ProxyFactory factory = new ProxyFactory(); factory.setFilter(IGNORE_BRIDGE_AND_OBJECT_METHODS); if (type.isInterface()) { factory.setInterfaces(new Class[] { type }); } else { factory.setSuperclass(type); } Class<?> proxyClass = factory.createClass(); Object proxyInstance = instanceCreator.instanceFor(proxyClass); setHandler(proxyInstance, handler); logger.debug("a proxy for {} is created as {}", type, proxyClass); return type.cast(proxyInstance); }
JavassistProxifier implements Proxifier { public <T> T proxify(Class<T> type, MethodInvocation<? super T> handler) { final ProxyFactory factory = new ProxyFactory(); factory.setFilter(IGNORE_BRIDGE_AND_OBJECT_METHODS); if (type.isInterface()) { factory.setInterfaces(new Class[] { type }); } else { factory.setSuperclass(type); } Class<?> proxyClass = factory.createClass(); Object proxyInstance = instanceCreator.instanceFor(proxyClass); setHandler(proxyInstance, handler); logger.debug("a proxy for {} is created as {}", type, proxyClass); return type.cast(proxyInstance); } }
JavassistProxifier implements Proxifier { public <T> T proxify(Class<T> type, MethodInvocation<? super T> handler) { final ProxyFactory factory = new ProxyFactory(); factory.setFilter(IGNORE_BRIDGE_AND_OBJECT_METHODS); if (type.isInterface()) { factory.setInterfaces(new Class[] { type }); } else { factory.setSuperclass(type); } Class<?> proxyClass = factory.createClass(); Object proxyInstance = instanceCreator.instanceFor(proxyClass); setHandler(proxyInstance, handler); logger.debug("a proxy for {} is created as {}", type, proxyClass); return type.cast(proxyInstance); } JavassistProxifier(InstanceCreator instanceCreator); }
JavassistProxifier implements Proxifier { public <T> T proxify(Class<T> type, MethodInvocation<? super T> handler) { final ProxyFactory factory = new ProxyFactory(); factory.setFilter(IGNORE_BRIDGE_AND_OBJECT_METHODS); if (type.isInterface()) { factory.setInterfaces(new Class[] { type }); } else { factory.setSuperclass(type); } Class<?> proxyClass = factory.createClass(); Object proxyInstance = instanceCreator.instanceFor(proxyClass); setHandler(proxyInstance, handler); logger.debug("a proxy for {} is created as {}", type, proxyClass); return type.cast(proxyInstance); } JavassistProxifier(InstanceCreator instanceCreator); T proxify(Class<T> type, MethodInvocation<? super T> handler); boolean isProxy(Object o); }
JavassistProxifier implements Proxifier { public <T> T proxify(Class<T> type, MethodInvocation<? super T> handler) { final ProxyFactory factory = new ProxyFactory(); factory.setFilter(IGNORE_BRIDGE_AND_OBJECT_METHODS); if (type.isInterface()) { factory.setInterfaces(new Class[] { type }); } else { factory.setSuperclass(type); } Class<?> proxyClass = factory.createClass(); Object proxyInstance = instanceCreator.instanceFor(proxyClass); setHandler(proxyInstance, handler); logger.debug("a proxy for {} is created as {}", type, proxyClass); return type.cast(proxyInstance); } JavassistProxifier(InstanceCreator instanceCreator); T proxify(Class<T> type, MethodInvocation<? super T> handler); boolean isProxy(Object o);  }