use of net.bytebuddy.description.method.MethodDescription in project byte-buddy by raphw.
the class ElementMatchersTest method testIsNative.
@Test
public void testIsNative() throws Exception {
MethodDescription methodDescription = mock(MethodDescription.class);
when(methodDescription.getModifiers()).thenReturn(Opcodes.ACC_NATIVE);
assertThat(ElementMatchers.isNative().matches(methodDescription), is(true));
assertThat(ElementMatchers.isNative().matches(mock(MethodDescription.class)), is(false));
}
use of net.bytebuddy.description.method.MethodDescription in project byte-buddy by raphw.
the class ElementMatchersTest method testNoneOfMethodDefinedShape.
@Test
public void testNoneOfMethodDefinedShape() throws Exception {
Method method = GenericMethodType.class.getDeclaredMethod("foo", Exception.class);
MethodDescription methodDescription = new TypeDescription.ForLoadedType(GenericMethodType.Inner.class).getInterfaces().getOnly().getDeclaredMethods().filter(named(FOO)).getOnly();
assertThat(ElementMatchers.noneOf(method).matches(methodDescription), is(false));
assertThat(ElementMatchers.definedMethod(ElementMatchers.noneOf(methodDescription.asDefined())).matches(methodDescription), is(false));
assertThat(ElementMatchers.noneOf(methodDescription.asDefined()).matches(methodDescription.asDefined()), is(false));
assertThat(ElementMatchers.noneOf(methodDescription.asDefined()).matches(methodDescription), is(true));
assertThat(ElementMatchers.noneOf(methodDescription).matches(methodDescription.asDefined()), is(true));
}
use of net.bytebuddy.description.method.MethodDescription in project byte-buddy by raphw.
the class ElementMatchersTest method testNoneOfConstructorDefinedShape.
@Test
public void testNoneOfConstructorDefinedShape() throws Exception {
Constructor<?> constructor = GenericConstructorType.class.getDeclaredConstructor(Exception.class);
MethodDescription methodDescription = new TypeDescription.ForLoadedType(GenericConstructorType.Inner.class).getSuperClass().getDeclaredMethods().filter(isConstructor()).getOnly();
assertThat(ElementMatchers.noneOf(constructor).matches(methodDescription), is(false));
assertThat(ElementMatchers.definedMethod(ElementMatchers.noneOf(methodDescription.asDefined())).matches(methodDescription), is(false));
assertThat(ElementMatchers.noneOf(methodDescription.asDefined()).matches(methodDescription.asDefined()), is(false));
assertThat(ElementMatchers.noneOf(methodDescription.asDefined()).matches(methodDescription), is(true));
assertThat(ElementMatchers.noneOf(methodDescription).matches(methodDescription.asDefined()), is(true));
}
use of net.bytebuddy.description.method.MethodDescription in project byte-buddy by raphw.
the class RebaseImplementationTargetTest method testNonRebasedMethodIsInvokable.
@Test
public void testNonRebasedMethodIsInvokable() throws Exception {
when(invokableMethod.getDeclaringType()).thenReturn(instrumentedType);
when(invokableMethod.isSpecializableFor(instrumentedType)).thenReturn(true);
when(resolution.isRebased()).thenReturn(false);
when(resolution.getResolvedMethod()).thenReturn(invokableMethod);
Implementation.SpecialMethodInvocation specialMethodInvocation = makeImplementationTarget().invokeSuper(rebasedSignatureToken);
assertThat(specialMethodInvocation.isValid(), is(true));
assertThat(specialMethodInvocation.getMethodDescription(), is((MethodDescription) invokableMethod));
assertThat(specialMethodInvocation.getTypeDescription(), is(instrumentedType));
MethodVisitor methodVisitor = mock(MethodVisitor.class);
Implementation.Context implementationContext = mock(Implementation.Context.class);
StackManipulation.Size size = specialMethodInvocation.apply(methodVisitor, implementationContext);
verify(methodVisitor).visitMethodInsn(Opcodes.INVOKESPECIAL, BAZ, FOO, QUX, false);
verifyNoMoreInteractions(methodVisitor);
verifyZeroInteractions(implementationContext);
assertThat(size.getSizeImpact(), is(0));
assertThat(size.getMaximalSize(), is(0));
}
use of net.bytebuddy.description.method.MethodDescription in project byte-buddy by raphw.
the class RebaseImplementationTargetTest method testSuperTypeMethodIsInvokable.
@Test
public void testSuperTypeMethodIsInvokable() throws Exception {
when(invokableMethod.isSpecializableFor(rawSuperClass)).thenReturn(true);
Implementation.SpecialMethodInvocation specialMethodInvocation = makeImplementationTarget().invokeSuper(invokableToken);
assertThat(specialMethodInvocation.isValid(), is(true));
assertThat(specialMethodInvocation.getMethodDescription(), is((MethodDescription) invokableMethod));
assertThat(specialMethodInvocation.getTypeDescription(), is(rawSuperClass));
MethodVisitor methodVisitor = mock(MethodVisitor.class);
Implementation.Context implementationContext = mock(Implementation.Context.class);
StackManipulation.Size size = specialMethodInvocation.apply(methodVisitor, implementationContext);
verify(methodVisitor).visitMethodInsn(Opcodes.INVOKESPECIAL, BAR, FOO, QUX, false);
verifyNoMoreInteractions(methodVisitor);
verifyZeroInteractions(implementationContext);
assertThat(size.getSizeImpact(), is(0));
assertThat(size.getMaximalSize(), is(0));
}
Aggregations