use of net.bytebuddy.implementation.bytecode.StackManipulation in project byte-buddy by raphw.
the class FieldAccessOtherTest method testGenericFieldAccessPutter.
@Test
public void testGenericFieldAccessPutter() throws Exception {
TypeDescription genericErasure = mock(TypeDescription.class), declaredErasure = mock(TypeDescription.class);
when(genericType.asErasure()).thenReturn(genericErasure);
when(declaredType.asErasure()).thenReturn(declaredErasure);
StackManipulation stackManipulation = FieldAccess.forField(genericField).write();
assertThat(stackManipulation.isValid(), is(true));
assertThat(stackManipulation, is(FieldAccess.forField(fieldDescription).write()));
}
use of net.bytebuddy.implementation.bytecode.StackManipulation in project byte-buddy by raphw.
the class FieldAccessOtherTest method testEnumerationDescriptionWithIllegalOwnership.
@Test
public void testEnumerationDescriptionWithIllegalOwnership() throws Exception {
when(fieldDescription.isPublic()).thenReturn(true);
when(fieldDescription.isStatic()).thenReturn(false);
when(fieldDescription.isEnum()).thenReturn(true);
when(fieldDescription.getActualName()).thenReturn(FOO);
StackManipulation stackManipulation = FieldAccess.forEnumeration(enumerationDescription);
assertThat(stackManipulation.isValid(), is(false));
}
use of net.bytebuddy.implementation.bytecode.StackManipulation in project byte-buddy by raphw.
the class FieldAccessOtherTest method testGenericFieldAccessGetter.
@Test
public void testGenericFieldAccessGetter() throws Exception {
TypeDescription genericErasure = mock(TypeDescription.class), declaredErasure = mock(TypeDescription.class);
when(genericErasure.asErasure()).thenReturn(genericErasure);
when(genericType.asErasure()).thenReturn(genericErasure);
when(declaredType.asErasure()).thenReturn(declaredErasure);
StackManipulation stackManipulation = FieldAccess.forField(genericField).read();
assertThat(stackManipulation.isValid(), is(true));
assertThat(stackManipulation, is((StackManipulation) new StackManipulation.Compound(FieldAccess.forField(fieldDescription).read(), TypeCasting.to(genericErasure))));
}
use of net.bytebuddy.implementation.bytecode.StackManipulation in project byte-buddy by raphw.
the class HandleInvocationTest method testInvocationIncreasingStack.
@Test
public void testInvocationIncreasingStack() throws Exception {
JavaConstant.MethodType methodType = JavaConstant.MethodType.of(Object.class);
StackManipulation stackManipulation = new HandleInvocation(methodType);
assertThat(stackManipulation.isValid(), is(true));
StackManipulation.Size size = stackManipulation.apply(methodVisitor, implementationContext);
assertThat(size.getSizeImpact(), is(1));
assertThat(size.getMaximalSize(), is(1));
verify(methodVisitor).visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/invoke/MethodHandle", "invokeExact", "()Ljava/lang/Object;", false);
verifyNoMoreInteractions(methodVisitor);
verifyZeroInteractions(implementationContext);
}
use of net.bytebuddy.implementation.bytecode.StackManipulation in project byte-buddy by raphw.
the class MethodInvocationGenericTest method testGenericMethodErasureEqual.
@Test
public void testGenericMethodErasureEqual() throws Exception {
when(methodReturnType.asErasure()).thenReturn(declaredErasure);
StackManipulation stackManipulation = MethodInvocation.invoke(methodDescription);
assertThat(stackManipulation.isValid(), is(true));
assertThat(stackManipulation, is((StackManipulation) MethodInvocation.invoke(declaredMethod)));
}
Aggregations