-
-
Notifications
You must be signed in to change notification settings - Fork 776
/
MethodInvocationOtherTest.java
51 lines (44 loc) · 2.55 KB
/
MethodInvocationOtherTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package net.bytebuddy.instrumentation.method.bytecode.stack.member;
import net.bytebuddy.instrumentation.Instrumentation;
import net.bytebuddy.instrumentation.method.MethodDescription;
import net.bytebuddy.instrumentation.method.bytecode.stack.StackManipulation;
import net.bytebuddy.instrumentation.method.bytecode.stack.StackSize;
import net.bytebuddy.instrumentation.type.TypeDescription;
import net.bytebuddy.instrumentation.type.TypeList;
import net.bytebuddy.test.utility.ObjectPropertyAssertion;
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;
import static org.mockito.Mockito.when;
public class MethodInvocationOtherTest {
private static final String FOO = "foo";
@Test
public void testObjectProperties() throws Exception {
ObjectPropertyAssertion.of(MethodInvocation.Invocation.class).refine(new ObjectPropertyAssertion.Refinement<MethodDescription>() {
@Override
public void apply(MethodDescription mock) {
when(mock.getDeclaringType()).thenReturn(mock(TypeDescription.class));
TypeDescription returnType = mock(TypeDescription.class);
when(returnType.getStackSize()).thenReturn(StackSize.ZERO);
when(mock.getReturnType()).thenReturn(returnType);
when(mock.getInternalName()).thenReturn(FOO);
when(mock.getParameterTypes()).thenReturn(new TypeList.Empty());
}
}).apply();
ObjectPropertyAssertion.of(MethodInvocation.DynamicInvocation.class).apply();
}
@Test(expected = IllegalStateException.class)
public void testIllegal() throws Exception {
assertThat(MethodInvocation.IllegalInvocation.INSTANCE.isValid(), is(false));
assertThat(MethodInvocation.IllegalInvocation.INSTANCE.special(mock(TypeDescription.class)),
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));
}
}