Skip to content

Commit

Permalink
Fixed reference of method instead of type.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafael Winterhalter committed Jan 6, 2016
1 parent bab7df6 commit a663cf7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
Expand Up @@ -474,7 +474,7 @@ public static MethodRebaseResolver make(TypeDescription instrumentedType,
DynamicType placeholderType = null; DynamicType placeholderType = null;
Map<MethodDescription.InDefinedShape, Resolution> resolutions = new HashMap<MethodDescription.InDefinedShape, Resolution>(); Map<MethodDescription.InDefinedShape, Resolution> resolutions = new HashMap<MethodDescription.InDefinedShape, Resolution>();
for (MethodDescription.InDefinedShape instrumentedMethod : instrumentedType.getDeclaredMethods()) { for (MethodDescription.InDefinedShape instrumentedMethod : instrumentedType.getDeclaredMethods()) {
if (rebaseableMethods.contains(instrumentedMethod.asToken(is(instrumentedMethod)))) { if (rebaseableMethods.contains(instrumentedMethod.asToken(is(instrumentedType)))) {
Resolution resolution; Resolution resolution;
if (instrumentedMethod.isConstructor()) { if (instrumentedMethod.isConstructor()) {
if (placeholderType == null) { if (placeholderType == null) {
Expand Down
Expand Up @@ -10,6 +10,7 @@
import net.bytebuddy.implementation.Implementation; import net.bytebuddy.implementation.Implementation;
import net.bytebuddy.implementation.bytecode.StackManipulation; import net.bytebuddy.implementation.bytecode.StackManipulation;
import net.bytebuddy.implementation.bytecode.constant.NullConstant; import net.bytebuddy.implementation.bytecode.constant.NullConstant;
import net.bytebuddy.matcher.ElementMatchers;
import net.bytebuddy.test.utility.ObjectPropertyAssertion; import net.bytebuddy.test.utility.ObjectPropertyAssertion;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
Expand All @@ -33,7 +34,10 @@ public class RebaseImplementationTargetTest extends AbstractImplementationTarget
private MethodDescription.InDefinedShape rebasedMethod; private MethodDescription.InDefinedShape rebasedMethod;


@Mock @Mock
private MethodDescription.SignatureToken rebasedToken; private MethodDescription.Token rebasedToken;

@Mock
private MethodDescription.SignatureToken rebasedSignatureToken;


@Mock @Mock
private MethodRebaseResolver.Resolution resolution; private MethodRebaseResolver.Resolution resolution;
Expand All @@ -52,12 +56,13 @@ public void setUp() throws Exception {
when(genericSuperType.asErasure()).thenReturn(superType); when(genericSuperType.asErasure()).thenReturn(superType);
when(superType.getInternalName()).thenReturn(BAR); when(superType.getInternalName()).thenReturn(BAR);
when(rebasedMethod.getInternalName()).thenReturn(QUX); when(rebasedMethod.getInternalName()).thenReturn(QUX);
when(rebasedMethod.asToken(ElementMatchers.is(instrumentedType))).thenReturn(rebasedToken);
when(rebasedMethod.getDescriptor()).thenReturn(FOO); when(rebasedMethod.getDescriptor()).thenReturn(FOO);
when(rebasedMethod.asDefined()).thenReturn(rebasedMethod); when(rebasedMethod.asDefined()).thenReturn(rebasedMethod);
when(rebasedMethod.getReturnType()).thenReturn(genericReturnType); when(rebasedMethod.getReturnType()).thenReturn(genericReturnType);
when(rebasedMethod.getParameters()).thenReturn(new ParameterList.Empty<ParameterDescription.InDefinedShape>()); when(rebasedMethod.getParameters()).thenReturn(new ParameterList.Empty<ParameterDescription.InDefinedShape>());
when(rebasedMethod.getDeclaringType()).thenReturn(instrumentedType); when(rebasedMethod.getDeclaringType()).thenReturn(instrumentedType);
when(rebasedMethod.asSignatureToken()).thenReturn(rebasedToken); when(rebasedMethod.asSignatureToken()).thenReturn(rebasedSignatureToken);
when(methodRebaseResolver.resolve(rebasedMethod)).thenReturn(resolution); when(methodRebaseResolver.resolve(rebasedMethod)).thenReturn(resolution);
super.setUp(); super.setUp();
} }
Expand All @@ -75,7 +80,7 @@ public void testNonRebasedMethodIsInvokable() throws Exception {
when(invokableMethod.isSpecializableFor(instrumentedType)).thenReturn(true); when(invokableMethod.isSpecializableFor(instrumentedType)).thenReturn(true);
when(resolution.isRebased()).thenReturn(false); when(resolution.isRebased()).thenReturn(false);
when(resolution.getResolvedMethod()).thenReturn(invokableMethod); when(resolution.getResolvedMethod()).thenReturn(invokableMethod);
Implementation.SpecialMethodInvocation specialMethodInvocation = implementationTarget.invokeSuper(rebasedToken); Implementation.SpecialMethodInvocation specialMethodInvocation = implementationTarget.invokeSuper(rebasedSignatureToken);
verify(methodRebaseResolver).asTokenMap(); verify(methodRebaseResolver).asTokenMap();
verifyNoMoreInteractions(methodRebaseResolver); verifyNoMoreInteractions(methodRebaseResolver);
assertThat(specialMethodInvocation.isValid(), is(true)); assertThat(specialMethodInvocation.isValid(), is(true));
Expand All @@ -98,7 +103,7 @@ public void testRebasedMethodIsInvokable() throws Exception {
when(resolution.getResolvedMethod()).thenReturn(rebasedMethod); when(resolution.getResolvedMethod()).thenReturn(rebasedMethod);
when(resolution.getAdditionalArguments()).thenReturn(StackManipulation.Trivial.INSTANCE); when(resolution.getAdditionalArguments()).thenReturn(StackManipulation.Trivial.INSTANCE);
when(rebasedMethod.isSpecializableFor(instrumentedType)).thenReturn(true); when(rebasedMethod.isSpecializableFor(instrumentedType)).thenReturn(true);
Implementation.SpecialMethodInvocation specialMethodInvocation = implementationTarget.invokeSuper(rebasedToken); Implementation.SpecialMethodInvocation specialMethodInvocation = implementationTarget.invokeSuper(rebasedSignatureToken);
verify(methodRebaseResolver).asTokenMap(); verify(methodRebaseResolver).asTokenMap();
verifyNoMoreInteractions(methodRebaseResolver); verifyNoMoreInteractions(methodRebaseResolver);
assertThat(specialMethodInvocation.isValid(), is(true)); assertThat(specialMethodInvocation.isValid(), is(true));
Expand All @@ -122,7 +127,7 @@ public void testRebasedConstructorIsInvokable() throws Exception {
when(resolution.getResolvedMethod()).thenReturn(rebasedMethod); when(resolution.getResolvedMethod()).thenReturn(rebasedMethod);
when(resolution.getAdditionalArguments()).thenReturn(NullConstant.INSTANCE); when(resolution.getAdditionalArguments()).thenReturn(NullConstant.INSTANCE);
when(rebasedMethod.isSpecializableFor(instrumentedType)).thenReturn(true); when(rebasedMethod.isSpecializableFor(instrumentedType)).thenReturn(true);
Implementation.SpecialMethodInvocation specialMethodInvocation = implementationTarget.invokeSuper(rebasedToken); Implementation.SpecialMethodInvocation specialMethodInvocation = implementationTarget.invokeSuper(rebasedSignatureToken);
verify(methodRebaseResolver).asTokenMap(); verify(methodRebaseResolver).asTokenMap();
verifyNoMoreInteractions(methodRebaseResolver); verifyNoMoreInteractions(methodRebaseResolver);
assertThat(specialMethodInvocation.isValid(), is(true)); assertThat(specialMethodInvocation.isValid(), is(true));
Expand All @@ -147,7 +152,7 @@ public void testNonSpecializableRebaseMethodIsNotInvokable() throws Exception {
when(resolution.getAdditionalArguments()).thenReturn(StackManipulation.Trivial.INSTANCE); when(resolution.getAdditionalArguments()).thenReturn(StackManipulation.Trivial.INSTANCE);
when(rebasedMethod.isSpecializableFor(instrumentedType)).thenReturn(false); when(rebasedMethod.isSpecializableFor(instrumentedType)).thenReturn(false);
when(methodRebaseResolver.resolve(invokableMethod)).thenReturn(new MethodRebaseResolver.Resolution.Preserved(invokableMethod)); when(methodRebaseResolver.resolve(invokableMethod)).thenReturn(new MethodRebaseResolver.Resolution.Preserved(invokableMethod));
Implementation.SpecialMethodInvocation specialMethodInvocation = implementationTarget.invokeSuper(rebasedToken); Implementation.SpecialMethodInvocation specialMethodInvocation = implementationTarget.invokeSuper(rebasedSignatureToken);
assertThat(specialMethodInvocation.isValid(), is(false)); assertThat(specialMethodInvocation.isValid(), is(false));
} }


Expand Down

0 comments on commit a663cf7

Please sign in to comment.