コード例 #1
0
 @Test
 public void testInstrumentationLegacyClassOtherType() throws Exception {
   ClassVisitor classVisitor =
       TypeConstantAdjustment.INSTANCE.wrap(
           mock(TypeDescription.class),
           this.classVisitor,
           mock(Implementation.Context.class),
           mock(TypePool.class),
           new FieldList.Empty<FieldDescription.InDefinedShape>(),
           new MethodList.Empty<MethodDescription>(),
           IGNORED,
           IGNORED);
   classVisitor.visit(
       ClassFileVersion.JAVA_V4.getMinorMajorVersion(), FOOBAR, FOO, BAR, QUX, new String[] {BAZ});
   MethodVisitor methodVisitor =
       classVisitor.visitMethod(FOOBAR, FOO, BAR, QUX, new String[] {BAZ});
   assertThat(methodVisitor, not(this.methodVisitor));
   methodVisitor.visitLdcInsn(FOO);
   verify(this.classVisitor)
       .visit(
           ClassFileVersion.JAVA_V4.getMinorMajorVersion(),
           FOOBAR,
           FOO,
           BAR,
           QUX,
           new String[] {BAZ});
   verify(this.classVisitor).visitMethod(FOOBAR, FOO, BAR, QUX, new String[] {BAZ});
   verifyNoMoreInteractions(this.classVisitor);
   verify(this.methodVisitor).visitLdcInsn(FOO);
   verifyNoMoreInteractions(this.methodVisitor);
 }
コード例 #2
0
 @Test
 public void testInstrumentationLegacyClassFileArrayType() throws Exception {
   ClassVisitor classVisitor =
       TypeConstantAdjustment.INSTANCE.wrap(
           mock(TypeDescription.class),
           this.classVisitor,
           mock(Implementation.Context.class),
           mock(TypePool.class),
           new FieldList.Empty<FieldDescription.InDefinedShape>(),
           new MethodList.Empty<MethodDescription>(),
           IGNORED,
           IGNORED);
   classVisitor.visit(
       ClassFileVersion.JAVA_V4.getMinorMajorVersion(), FOOBAR, FOO, BAR, QUX, new String[] {BAZ});
   MethodVisitor methodVisitor =
       classVisitor.visitMethod(FOOBAR, FOO, BAR, QUX, new String[] {BAZ});
   assertThat(methodVisitor, not(this.methodVisitor));
   methodVisitor.visitLdcInsn(Type.getType(Object[].class));
   verify(this.classVisitor)
       .visit(
           ClassFileVersion.JAVA_V4.getMinorMajorVersion(),
           FOOBAR,
           FOO,
           BAR,
           QUX,
           new String[] {BAZ});
   verify(this.classVisitor).visitMethod(FOOBAR, FOO, BAR, QUX, new String[] {BAZ});
   verifyNoMoreInteractions(this.classVisitor);
   verify(this.methodVisitor)
       .visitLdcInsn(Type.getType(Object[].class).getInternalName().replace('/', '.'));
   verify(this.methodVisitor)
       .visitMethodInsn(
           Opcodes.INVOKESTATIC,
           Type.getType(Class.class).getInternalName(),
           "forName",
           Type.getType(Class.class.getDeclaredMethod("forName", String.class)).getDescriptor(),
           false);
   verifyNoMoreInteractions(this.methodVisitor);
 }