use of net.bytebuddy.implementation.bytecode.StackManipulation in project byte-buddy by raphw.
the class ReferenceTypeAwareAssignerTest method testPrimitiveAssignabilityWhenNotEqual.
@Test(expected = IllegalStateException.class)
public void testPrimitiveAssignabilityWhenNotEqual() throws Exception {
// Note: cannot mock equals
TypeDescription.Generic primitiveType = new TypeDescription.Generic.OfNonGenericType.ForLoadedType(int.class);
// Note: cannot mock equals
TypeDescription.Generic otherPrimitiveType = new TypeDescription.Generic.OfNonGenericType.ForLoadedType(long.class);
StackManipulation stackManipulation = ReferenceTypeAwareAssigner.INSTANCE.assign(primitiveType, otherPrimitiveType, Assigner.Typing.DYNAMIC);
assertThat(stackManipulation.isValid(), is(false));
stackManipulation.apply(methodVisitor, implementationContext);
}
use of net.bytebuddy.implementation.bytecode.StackManipulation in project byte-buddy by raphw.
the class ClassConstantPrimitiveTest method testClassConstant.
@Test
public void testClassConstant() throws Exception {
StackManipulation stackManipulation = ClassConstant.of(primitiveType);
assertThat(stackManipulation.isValid(), is(true));
StackManipulation.Size size = stackManipulation.apply(methodVisitor, implementationContext);
assertThat(size.getSizeImpact(), is(1));
assertThat(size.getMaximalSize(), is(1));
verify(methodVisitor).visitFieldInsn(Opcodes.GETSTATIC, wrapperType.getInternalName(), "TYPE", "Ljava/lang/Class;");
verifyNoMoreInteractions(methodVisitor);
verifyZeroInteractions(implementationContext);
}
use of net.bytebuddy.implementation.bytecode.StackManipulation in project byte-buddy by raphw.
the class ClassConstantReferenceTest method testClassConstantModernVisible.
@Test
public void testClassConstantModernVisible() throws Exception {
when(typeDescription.isVisibleTo(instrumentedType)).thenReturn(true);
when(classFileVersion.isAtLeast(ClassFileVersion.JAVA_V5)).thenReturn(true);
when(typeDescription.getDescriptor()).thenReturn(FOO);
StackManipulation stackManipulation = ClassConstant.of(typeDescription);
assertThat(stackManipulation.isValid(), is(true));
StackManipulation.Size size = stackManipulation.apply(methodVisitor, implementationContext);
assertThat(size.getSizeImpact(), is(1));
assertThat(size.getMaximalSize(), is(1));
verify(typeDescription).getDescriptor();
verify(typeDescription).isVisibleTo(instrumentedType);
verify(typeDescription, times(9)).represents(any(Class.class));
verifyNoMoreInteractions(typeDescription);
verify(methodVisitor).visitLdcInsn(Type.getType(FOO));
verifyNoMoreInteractions(methodVisitor);
}
use of net.bytebuddy.implementation.bytecode.StackManipulation in project byte-buddy by raphw.
the class ClassConstantReferenceTest method testClassConstantModernInvisible.
@Test
public void testClassConstantModernInvisible() throws Exception {
when(typeDescription.isVisibleTo(instrumentedType)).thenReturn(false);
when(classFileVersion.isAtLeast(ClassFileVersion.JAVA_V5)).thenReturn(true);
when(typeDescription.getName()).thenReturn(FOO);
StackManipulation stackManipulation = ClassConstant.of(typeDescription);
assertThat(stackManipulation.isValid(), is(true));
StackManipulation.Size size = stackManipulation.apply(methodVisitor, implementationContext);
assertThat(size.getSizeImpact(), is(1));
assertThat(size.getMaximalSize(), is(1));
verify(typeDescription).getName();
verify(typeDescription).isVisibleTo(instrumentedType);
verify(typeDescription, times(9)).represents(any(Class.class));
verifyNoMoreInteractions(typeDescription);
verify(methodVisitor).visitLdcInsn(FOO);
verify(methodVisitor).visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(Class.class), "forName", Type.getMethodDescriptor(Type.getType(Class.class), Type.getType(String.class)), false);
verifyNoMoreInteractions(methodVisitor);
}
use of net.bytebuddy.implementation.bytecode.StackManipulation in project byte-buddy by raphw.
the class FieldConstantTest method testConstantCreationModernVisible.
@Test
public void testConstantCreationModernVisible() throws Exception {
when(classFileVersion.isAtLeast(ClassFileVersion.JAVA_V5)).thenReturn(true);
when(declaringType.isVisibleTo(instrumentedType)).thenReturn(true);
StackManipulation stackManipulation = new FieldConstant(fieldDescription);
assertThat(stackManipulation.isValid(), is(true));
StackManipulation.Size size = stackManipulation.apply(methodVisitor, implementationContext);
assertThat(size.getSizeImpact(), is(1));
assertThat(size.getMaximalSize(), is(2));
verify(methodVisitor).visitLdcInsn(Type.getObjectType(QUX));
verify(methodVisitor).visitLdcInsn(BAR);
verify(methodVisitor).visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Class", "getDeclaredField", "(Ljava/lang/String;)Ljava/lang/reflect/Field;", false);
verifyNoMoreInteractions(methodVisitor);
}
Aggregations