@Test
 public void testAbstractSuperTypeMethodIsNotInvokable() throws Exception {
   when(superMethod.isSpecializableFor(superType)).thenReturn(true);
   when(superMethod.isAbstract()).thenReturn(true);
   Implementation.SpecialMethodInvocation specialMethodInvocation =
       implementationTarget.invokeSuper(superMethod, methodLookup);
   assertThat(specialMethodInvocation.isValid(), is(false));
 }
Beispiel #2
0
 /**
  * Creates a method handle representation of the given method for an explicit special method
  * invocation of an otherwise virtual method.
  *
  * @param methodDescription The method ro represent.
  * @param typeDescription The type on which the method is to be invoked on as a special method
  *     invocation.
  * @return A method handle representing the given method as special method invocation.
  */
 public static MethodHandle ofSpecial(
     MethodDescription methodDescription, TypeDescription typeDescription) {
   if (!methodDescription.isSpecializableFor(typeDescription)) {
     throw new IllegalArgumentException(
         "Cannot specialize " + methodDescription + " for " + typeDescription);
   }
   return new MethodHandle(
       HandleType.ofSpecial(methodDescription),
       typeDescription,
       methodDescription.getInternalName(),
       methodDescription.getReturnType().asRawType(),
       methodDescription.getParameters().asTypeList().asRawTypes());
 }
 @Test
 public void testSuperTypeMethodIsInvokable() throws Exception {
   when(superMethod.isSpecializableFor(superType)).thenReturn(true);
   Implementation.SpecialMethodInvocation specialMethodInvocation =
       implementationTarget.invokeSuper(superMethod, methodLookup);
   assertThat(specialMethodInvocation.isValid(), is(true));
   assertThat(specialMethodInvocation.getMethodDescription(), is(superMethod));
   assertThat(specialMethodInvocation.getTypeDescription(), is(superType));
   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, BAZ, FOOBAR, false);
   verifyNoMoreInteractions(methodVisitor);
   verifyZeroInteractions(implementationContext);
   assertThat(size.getSizeImpact(), is(0));
   assertThat(size.getMaximalSize(), is(0));
 }
 @Override
 @Before
 public void setUp() throws Exception {
   when(parameterList.asTypeList()).thenReturn(parameterTypes);
   when(instrumentedType.getSupertype()).thenReturn(superType);
   when(superType.getDeclaredMethods())
       .thenReturn(new MethodList.Explicit(Collections.singletonList(superMethodConstructor)));
   when(superType.getInternalName()).thenReturn(BAR);
   when(superMethod.getDeclaringType()).thenReturn(superType);
   when(superType.getStackSize()).thenReturn(StackSize.ZERO);
   when(superMethod.getReturnType()).thenReturn(returnType);
   when(superMethod.getInternalName()).thenReturn(BAZ);
   when(superMethod.getDescriptor()).thenReturn(FOOBAR);
   when(superMethod.getParameters()).thenReturn(parameterList);
   when(superMethodConstructor.isConstructor()).thenReturn(true);
   when(superMethodConstructor.getParameters()).thenReturn(parameterList);
   when(superMethodConstructor.getReturnType()).thenReturn(returnType);
   when(superMethodConstructor.isSpecializableFor(superType)).thenReturn(true);
   when(superMethodConstructor.getInternalName()).thenReturn(QUXBAZ);
   when(superMethodConstructor.getDescriptor()).thenReturn(BAZBAR);
   super.setUp();
 }