예제 #1
0
 @Test
 public void shouldTryAllConstructorsInDeclarationOrder() {
   Proxifier proxifier = new DefaultProxifier();
   TheClassWithManyConstructors proxy =
       (TheClassWithManyConstructors)
           proxifier.proxify(
               TheClassWithManyConstructors.class,
               new MethodInvocation() {
                 public Object intercept(
                     Object proxy, Method method, Object[] args, SuperMethod superMethod) {
                   return superMethod.invoke(proxy, args);
                 }
               });
   assertTrue(proxy.wasNumberConstructorCalled());
   assertThat(proxy.getNumber(), is(nullValue()));
 }
예제 #2
0
 @Test
 public void shouldNeverCallSuperclassConstructors() {
   Proxifier proxifier = new ObjenesisProxifier();
   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);
             }
           });
   assertFalse(proxy.wasNumberConstructorCalled());
   assertThat(proxy.getNumber(), is(nullValue()));
 }