@Before public void setUp() throws Exception { when(methodDescription.getDeclaringType()).thenReturn(typeDescription); when(methodDescription.getReturnType()).thenReturn(returnType); when(methodDescription.getInternalName()).thenReturn(FOO); when(methodDescription.getDescriptor()).thenReturn(BAZ); when(typeDescription.getInternalName()).thenReturn(BAR); when(typeDescription.getDescriptor()).thenReturn(BAR); when(methodNameTransformer.transform(FOO)).thenReturn(QUX); when(otherMethodNameTransformer.transform(FOO)).thenReturn(FOO + BAR); when(parameterType.getStackSize()).thenReturn(StackSize.ZERO); ParameterList parameterList = ParameterList.Explicit.latent(methodDescription, Collections.singletonList(parameterType)); when(methodDescription.getParameters()).thenReturn(parameterList); }
@Test public void testPreservation() throws Exception { MethodRebaseResolver.Resolution resolution = new MethodRebaseResolver.Resolution.ForRebasedMethod( methodDescription, methodNameTransformer); assertThat(resolution.isRebased(), is(true)); assertThat(resolution.getResolvedMethod().getDeclaringType(), is(typeDescription)); assertThat(resolution.getResolvedMethod().getInternalName(), is(QUX)); assertThat( resolution.getResolvedMethod().getModifiers(), is(MethodRebaseResolver.REBASED_METHOD_MODIFIER)); assertThat(resolution.getResolvedMethod().getReturnType(), is(returnType)); assertThat( resolution.getResolvedMethod().getParameters(), is( ParameterList.Explicit.latent( resolution.getResolvedMethod(), Collections.singletonList(parameterType)))); StackManipulation.Size size = resolution.getAdditionalArguments().apply(methodVisitor, instrumentationContext); assertThat(size.getSizeImpact(), is(0)); assertThat(size.getMaximalSize(), is(0)); verifyZeroInteractions(methodVisitor); verifyZeroInteractions(instrumentationContext); }