Skip to content

Commit

Permalink
Added additional test cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafael Winterhalter committed Feb 19, 2015
1 parent 91725af commit 8e18ba0
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
Expand Up @@ -882,7 +882,7 @@ protected AccessorMethodInvocation(MethodDescription instrumentedMethod,

@Override
public boolean isValid() {
return true;
return specialMethodInvocation.isValid();
}

@Override
Expand Down
Expand Up @@ -10,6 +10,8 @@
import org.junit.Test;
import org.objectweb.asm.MethodVisitor;

import java.util.List;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.Mockito.mock;
Expand Down Expand Up @@ -42,6 +44,8 @@ public void testIllegal() throws Exception {
is((StackManipulation) StackManipulation.Illegal.INSTANCE));
assertThat(MethodInvocation.IllegalInvocation.INSTANCE.virtual(mock(TypeDescription.class)),
is((StackManipulation) StackManipulation.Illegal.INSTANCE));
assertThat(MethodInvocation.IllegalInvocation.INSTANCE.dynamic(FOO, mock(TypeDescription.class), mock(TypeList.class), mock(List.class)),
is((StackManipulation) StackManipulation.Illegal.INSTANCE));
MethodInvocation.IllegalInvocation.INSTANCE.apply(mock(MethodVisitor.class), mock(Instrumentation.Context.class));
}
}
Expand Up @@ -3,12 +3,15 @@
import net.bytebuddy.ClassFileVersion;
import net.bytebuddy.instrumentation.Instrumentation;
import net.bytebuddy.instrumentation.ModifierContributor;
import net.bytebuddy.instrumentation.field.FieldDescription;
import net.bytebuddy.instrumentation.field.FieldList;
import net.bytebuddy.instrumentation.method.MethodDescription;
import net.bytebuddy.instrumentation.method.MethodList;
import net.bytebuddy.instrumentation.method.MethodLookupEngine;
import net.bytebuddy.instrumentation.method.bytecode.stack.StackManipulation;
import net.bytebuddy.instrumentation.type.TypeDescription;
import net.bytebuddy.instrumentation.type.TypeList;
import net.bytebuddy.matcher.ElementMatcher;
import net.bytebuddy.test.utility.MockitoRule;
import net.bytebuddy.test.utility.MoreOpcodes;
import org.junit.Before;
Expand Down Expand Up @@ -311,10 +314,33 @@ public void testForReflectionFactoryConstruction() throws Exception {
}

@Test
public void testInstrumentationsValid() throws Exception {
public void testInstrumentationIsValid() throws Exception {
assertThat(TypeProxy.AbstractMethodErrorThrow.INSTANCE.isValid(), is(true));
}

@Test
@SuppressWarnings("unchecked")
public void testAccessorIsValid() throws Exception {
TypeProxy typeProxy = new TypeProxy(mock(TypeDescription.class),
mock(Instrumentation.Target.class),
mock(TypeProxy.InvocationFactory.class),
false,
false);
TypeProxy.MethodCall methodCall = typeProxy.new MethodCall(mock(AuxiliaryType.MethodAccessorFactory.class));
TypeDescription instrumentedType = mock(TypeDescription.class);
FieldList fieldList = mock(FieldList.class);
when(fieldList.filter(any(ElementMatcher.class))).thenReturn(fieldList);
when(fieldList.getOnly()).thenReturn(mock(FieldDescription.class));
when(instrumentedType.getDeclaredFields()).thenReturn(fieldList);
TypeProxy.MethodCall.Appender appender = methodCall.new Appender(instrumentedType);
Instrumentation.SpecialMethodInvocation specialMethodInvocation = mock(Instrumentation.SpecialMethodInvocation.class);
when(specialMethodInvocation.isValid()).thenReturn(true);
StackManipulation stackManipulation = appender.new AccessorMethodInvocation(mock(MethodDescription.class), specialMethodInvocation);
assertThat(stackManipulation.isValid(), is(true));
verify(specialMethodInvocation).isValid();
verifyNoMoreInteractions(specialMethodInvocation);
}

public static class Foo {

private Void target;
Expand Down

0 comments on commit 8e18ba0

Please sign in to comment.