Skip to content

Commit

Permalink
Fixed test for super method invocation that now uses "invokeDominant".
Browse files Browse the repository at this point in the history
  • Loading branch information
raphw committed Aug 1, 2015
1 parent 4a463ec commit 6940d3b
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 28 deletions.
Expand Up @@ -679,6 +679,39 @@ public MethodRegistry.Compiled compile(Implementation.Target.Factory implementat
} }
return new Compiled(instrumentedType, loadedTypeInitializer, typeInitializer, entries); return new Compiled(instrumentedType, loadedTypeInitializer, typeInitializer, entries);
} }

@Override
public boolean equals(Object other) {
if (this == other) return true;
if (other == null || getClass() != other.getClass()) return false;
Prepared prepared = (Prepared) other;
return implementations.equals(prepared.implementations)
&& loadedTypeInitializer.equals(prepared.loadedTypeInitializer)
&& typeInitializer.equals(prepared.typeInitializer)
&& instrumentedType.equals(prepared.instrumentedType)
&& methodGraph.equals(prepared.methodGraph);
}

@Override
public int hashCode() {
int result = implementations.hashCode();
result = 31 * result + loadedTypeInitializer.hashCode();
result = 31 * result + typeInitializer.hashCode();
result = 31 * result + instrumentedType.hashCode();
result = 31 * result + methodGraph.hashCode();
return result;
}

@Override
public String toString() {
return "MethodRegistry.Default.Prepared{" +
"implementations=" + implementations +
", loadedTypeInitializer=" + loadedTypeInitializer +
", typeInitializer=" + typeInitializer +
", instrumentedType=" + instrumentedType +
", methodGraph=" + methodGraph +
'}';
}
} }


/** /**
Expand Down
Expand Up @@ -46,10 +46,7 @@ public class MethodRegistryDefaultTest {
private MethodAttributeAppender firstAppender, secondAppender; private MethodAttributeAppender firstAppender, secondAppender;


@Mock @Mock
private InstrumentedType firstType, secondType, thirdType; private InstrumentedType firstType, secondType, typeDescription;

@Mock
private TypeDescription typeDescription;


@Mock @Mock
private MethodDescription instrumentedMethod, firstMethod, secondMethod, thirdMethod; private MethodDescription instrumentedMethod, firstMethod, secondMethod, thirdMethod;
Expand All @@ -58,7 +55,7 @@ public class MethodRegistryDefaultTest {
private MethodGraph.Compiler methodGraphCompiler; private MethodGraph.Compiler methodGraphCompiler;


@Mock @Mock
private MethodGraph methodGraph; private MethodGraph.Linked methodGraph;


@Mock @Mock
private InstrumentedType.TypeInitializer typeInitializer; private InstrumentedType.TypeInitializer typeInitializer;
Expand All @@ -79,24 +76,23 @@ public class MethodRegistryDefaultTest {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void setUp() throws Exception { public void setUp() throws Exception {
when(firstHandler.prepare(firstType)).thenReturn(secondType); when(firstHandler.prepare(firstType)).thenReturn(secondType);
when(secondHandler.prepare(secondType)).thenReturn(thirdType); when(secondHandler.prepare(secondType)).thenReturn(typeDescription);
when(firstHandler.compile(implementationTarget)).thenReturn(firstCompiledHandler); when(firstHandler.compile(implementationTarget)).thenReturn(firstCompiledHandler);
when(secondHandler.compile(implementationTarget)).thenReturn(secondCompiledHandler); when(secondHandler.compile(implementationTarget)).thenReturn(secondCompiledHandler);
when(thirdType.getTypeInitializer()).thenReturn(typeInitializer); when(typeDescription.getTypeInitializer()).thenReturn(typeInitializer);
when(thirdType.getLoadedTypeInitializer()).thenReturn(loadedTypeInitializer); when(typeDescription.getLoadedTypeInitializer()).thenReturn(loadedTypeInitializer);
// when(methodLookupEngine.process(thirdType)).thenReturn(finding); when(methodGraphCompiler.compile(typeDescription)).thenReturn(methodGraph);
when(methodGraph.listNodes()).thenReturn(new MethodGraph.NodeList(Collections.singletonList(new MethodGraph.Node.Simple(instrumentedMethod))));
// when(finding.getTypeDescription()).thenReturn(typeDescription); // when(finding.getTypeDescription()).thenReturn(typeDescription);
// when(finding.getInvokableMethods()).thenReturn(new MethodList.Explicit(Collections.singletonList(instrumentedMethod)));
when(firstType.getDeclaredMethods()).thenReturn(new MethodList.Explicit(Collections.singletonList(firstMethod))); when(firstType.getDeclaredMethods()).thenReturn(new MethodList.Explicit(Collections.singletonList(firstMethod)));
when(secondType.getDeclaredMethods()).thenReturn(new MethodList.Explicit(Collections.singletonList(secondMethod))); when(secondType.getDeclaredMethods()).thenReturn(new MethodList.Explicit(Collections.singletonList(secondMethod)));
when(thirdType.getDeclaredMethods()).thenReturn(new MethodList.Explicit(Collections.singletonList(thirdMethod))); when(typeDescription.getDeclaredMethods()).thenReturn(new MethodList.Explicit(Collections.singletonList(thirdMethod)));
when(methodFilter.resolve(thirdType)).thenReturn((ElementMatcher) resolvedMethodFilter); when(methodFilter.resolve(typeDescription)).thenReturn((ElementMatcher) resolvedMethodFilter);
when(firstMatcher.resolve(thirdType)).thenReturn((ElementMatcher) firstFilter); when(firstMatcher.resolve(typeDescription)).thenReturn((ElementMatcher) firstFilter);
when(secondMatcher.resolve(thirdType)).thenReturn((ElementMatcher) secondFilter); when(secondMatcher.resolve(typeDescription)).thenReturn((ElementMatcher) secondFilter);
when(firstFactory.make(typeDescription)).thenReturn(firstAppender); when(firstFactory.make(typeDescription)).thenReturn(firstAppender);
when(secondFactory.make(typeDescription)).thenReturn(secondAppender); when(secondFactory.make(typeDescription)).thenReturn(secondAppender);
// when(implementationTargetFactory.make(finding, new MethodList.Explicit(Collections.singletonList(instrumentedMethod)))) when(implementationTargetFactory.make(typeDescription, methodGraph)).thenReturn(implementationTarget);
// .thenReturn(implementationTarget);
when(firstCompiledHandler.assemble(firstAppender, instrumentedMethod)).thenReturn(firstRecord); when(firstCompiledHandler.assemble(firstAppender, instrumentedMethod)).thenReturn(firstRecord);
when(secondCompiledHandler.assemble(secondAppender, instrumentedMethod)).thenReturn(secondRecord); when(secondCompiledHandler.assemble(secondAppender, instrumentedMethod)).thenReturn(secondRecord);
} }
Expand All @@ -108,7 +104,7 @@ public void testNonMatchedIsNotIncluded() throws Exception {
.append(firstMatcher, firstHandler, firstFactory) .append(firstMatcher, firstHandler, firstFactory)
.append(secondMatcher, secondHandler, secondFactory) .append(secondMatcher, secondHandler, secondFactory)
.prepare(firstType, methodGraphCompiler, methodFilter); .prepare(firstType, methodGraphCompiler, methodFilter);
assertThat(methodRegistry.getInstrumentedType(), is(typeDescription)); assertThat(methodRegistry.getInstrumentedType(), is((TypeDescription) typeDescription));
assertThat(methodRegistry.getInstrumentedMethods().size(), is(0)); assertThat(methodRegistry.getInstrumentedMethods().size(), is(0));
assertThat(methodRegistry.getTypeInitializer(), is(typeInitializer)); assertThat(methodRegistry.getTypeInitializer(), is(typeInitializer));
assertThat(methodRegistry.getLoadedTypeInitializer(), is(loadedTypeInitializer)); assertThat(methodRegistry.getLoadedTypeInitializer(), is(loadedTypeInitializer));
Expand All @@ -124,7 +120,7 @@ public void testIgnoredIsNotIncluded() throws Exception {
.append(firstMatcher, firstHandler, firstFactory) .append(firstMatcher, firstHandler, firstFactory)
.append(secondMatcher, secondHandler, secondFactory) .append(secondMatcher, secondHandler, secondFactory)
.prepare(firstType, methodGraphCompiler, methodFilter); .prepare(firstType, methodGraphCompiler, methodFilter);
assertThat(methodRegistry.getInstrumentedType(), is(typeDescription)); assertThat(methodRegistry.getInstrumentedType(), is((TypeDescription) typeDescription));
assertThat(methodRegistry.getInstrumentedMethods().size(), is(0)); assertThat(methodRegistry.getInstrumentedMethods().size(), is(0));
assertThat(methodRegistry.getTypeInitializer(), is(typeInitializer)); assertThat(methodRegistry.getTypeInitializer(), is(typeInitializer));
assertThat(methodRegistry.getLoadedTypeInitializer(), is(loadedTypeInitializer)); assertThat(methodRegistry.getLoadedTypeInitializer(), is(loadedTypeInitializer));
Expand All @@ -141,7 +137,7 @@ public void testMatchedFirst() throws Exception {
.append(firstMatcher, firstHandler, firstFactory) .append(firstMatcher, firstHandler, firstFactory)
.append(secondMatcher, secondHandler, secondFactory) .append(secondMatcher, secondHandler, secondFactory)
.prepare(firstType, methodGraphCompiler, methodFilter); .prepare(firstType, methodGraphCompiler, methodFilter);
assertThat(methodRegistry.getInstrumentedType(), is(typeDescription)); assertThat(methodRegistry.getInstrumentedType(), is((TypeDescription) typeDescription));
assertThat(methodRegistry.getInstrumentedMethods(), is((MethodList) new MethodList.Explicit(Collections.singletonList(instrumentedMethod)))); assertThat(methodRegistry.getInstrumentedMethods(), is((MethodList) new MethodList.Explicit(Collections.singletonList(instrumentedMethod))));
assertThat(methodRegistry.getTypeInitializer(), is(typeInitializer)); assertThat(methodRegistry.getTypeInitializer(), is(typeInitializer));
assertThat(methodRegistry.getLoadedTypeInitializer(), is(loadedTypeInitializer)); assertThat(methodRegistry.getLoadedTypeInitializer(), is(loadedTypeInitializer));
Expand All @@ -158,7 +154,7 @@ public void testMatchedSecond() throws Exception {
.append(firstMatcher, firstHandler, firstFactory) .append(firstMatcher, firstHandler, firstFactory)
.append(secondMatcher, secondHandler, secondFactory) .append(secondMatcher, secondHandler, secondFactory)
.prepare(firstType, methodGraphCompiler, methodFilter); .prepare(firstType, methodGraphCompiler, methodFilter);
assertThat(methodRegistry.getInstrumentedType(), is(typeDescription)); assertThat(methodRegistry.getInstrumentedType(), is((TypeDescription) typeDescription));
assertThat(methodRegistry.getInstrumentedMethods(), is((MethodList) new MethodList.Explicit(Collections.singletonList(instrumentedMethod)))); assertThat(methodRegistry.getInstrumentedMethods(), is((MethodList) new MethodList.Explicit(Collections.singletonList(instrumentedMethod))));
assertThat(methodRegistry.getTypeInitializer(), is(typeInitializer)); assertThat(methodRegistry.getTypeInitializer(), is(typeInitializer));
assertThat(methodRegistry.getLoadedTypeInitializer(), is(loadedTypeInitializer)); assertThat(methodRegistry.getLoadedTypeInitializer(), is(loadedTypeInitializer));
Expand All @@ -182,7 +178,7 @@ public void testMultipleRegistryDoesNotPrepareMultipleTimes() throws Exception {
.append(firstMatcher, firstHandler, secondFactory) .append(firstMatcher, firstHandler, secondFactory)
.append(firstMatcher, secondHandler, firstFactory) .append(firstMatcher, secondHandler, firstFactory)
.prepare(firstType, methodGraphCompiler, methodFilter); .prepare(firstType, methodGraphCompiler, methodFilter);
assertThat(methodRegistry.getInstrumentedType(), is(typeDescription)); assertThat(methodRegistry.getInstrumentedType(), is((TypeDescription) typeDescription));
assertThat(methodRegistry.getInstrumentedMethods(), is((MethodList) new MethodList.Explicit(Collections.singletonList(instrumentedMethod)))); assertThat(methodRegistry.getInstrumentedMethods(), is((MethodList) new MethodList.Explicit(Collections.singletonList(instrumentedMethod))));
assertThat(methodRegistry.getTypeInitializer(), is(typeInitializer)); assertThat(methodRegistry.getTypeInitializer(), is(typeInitializer));
assertThat(methodRegistry.getLoadedTypeInitializer(), is(loadedTypeInitializer)); assertThat(methodRegistry.getLoadedTypeInitializer(), is(loadedTypeInitializer));
Expand All @@ -202,7 +198,7 @@ public void testCompiledAppendingMatchesFirstAppended() throws Exception {
.append(secondMatcher, secondHandler, secondFactory) .append(secondMatcher, secondHandler, secondFactory)
.prepare(firstType, methodGraphCompiler, methodFilter) .prepare(firstType, methodGraphCompiler, methodFilter)
.compile(implementationTargetFactory); .compile(implementationTargetFactory);
assertThat(methodRegistry.getInstrumentedType(), is(typeDescription)); assertThat(methodRegistry.getInstrumentedType(), is((TypeDescription) typeDescription));
assertThat(methodRegistry.getInstrumentedMethods(), is((MethodList) new MethodList.Explicit(Collections.singletonList(instrumentedMethod)))); assertThat(methodRegistry.getInstrumentedMethods(), is((MethodList) new MethodList.Explicit(Collections.singletonList(instrumentedMethod))));
assertThat(methodRegistry.getTypeInitializer(), is(typeInitializer)); assertThat(methodRegistry.getTypeInitializer(), is(typeInitializer));
assertThat(methodRegistry.getLoadedTypeInitializer(), is(loadedTypeInitializer)); assertThat(methodRegistry.getLoadedTypeInitializer(), is(loadedTypeInitializer));
Expand All @@ -225,7 +221,7 @@ public void testCompiledPrependingMatchesLastPrepended() throws Exception {
.prepend(firstMatcher, firstHandler, firstFactory) .prepend(firstMatcher, firstHandler, firstFactory)
.prepare(firstType, methodGraphCompiler, methodFilter) .prepare(firstType, methodGraphCompiler, methodFilter)
.compile(implementationTargetFactory); .compile(implementationTargetFactory);
assertThat(methodRegistry.getInstrumentedType(), is(typeDescription)); assertThat(methodRegistry.getInstrumentedType(), is((TypeDescription) typeDescription));
assertThat(methodRegistry.getInstrumentedMethods(), is((MethodList) new MethodList.Explicit(Collections.singletonList(instrumentedMethod)))); assertThat(methodRegistry.getInstrumentedMethods(), is((MethodList) new MethodList.Explicit(Collections.singletonList(instrumentedMethod))));
assertThat(methodRegistry.getTypeInitializer(), is(typeInitializer)); assertThat(methodRegistry.getTypeInitializer(), is(typeInitializer));
assertThat(methodRegistry.getLoadedTypeInitializer(), is(loadedTypeInitializer)); assertThat(methodRegistry.getLoadedTypeInitializer(), is(loadedTypeInitializer));
Expand All @@ -248,7 +244,7 @@ public void testCompiledAppendingMatchesSecondAppendedIfFirstDoesNotMatch() thro
.append(secondMatcher, secondHandler, secondFactory) .append(secondMatcher, secondHandler, secondFactory)
.prepare(firstType, methodGraphCompiler, methodFilter) .prepare(firstType, methodGraphCompiler, methodFilter)
.compile(implementationTargetFactory); .compile(implementationTargetFactory);
assertThat(methodRegistry.getInstrumentedType(), is(typeDescription)); assertThat(methodRegistry.getInstrumentedType(), is((TypeDescription) typeDescription));
assertThat(methodRegistry.getInstrumentedMethods(), is((MethodList) new MethodList.Explicit(Collections.singletonList(instrumentedMethod)))); assertThat(methodRegistry.getInstrumentedMethods(), is((MethodList) new MethodList.Explicit(Collections.singletonList(instrumentedMethod))));
assertThat(methodRegistry.getTypeInitializer(), is(typeInitializer)); assertThat(methodRegistry.getTypeInitializer(), is(typeInitializer));
assertThat(methodRegistry.getLoadedTypeInitializer(), is(loadedTypeInitializer)); assertThat(methodRegistry.getLoadedTypeInitializer(), is(loadedTypeInitializer));
Expand All @@ -270,7 +266,7 @@ public void testSkipEntryIfNotMatched() throws Exception {
.append(secondMatcher, secondHandler, secondFactory) .append(secondMatcher, secondHandler, secondFactory)
.prepare(firstType, methodGraphCompiler, methodFilter) .prepare(firstType, methodGraphCompiler, methodFilter)
.compile(implementationTargetFactory); .compile(implementationTargetFactory);
assertThat(methodRegistry.getInstrumentedType(), is(typeDescription)); assertThat(methodRegistry.getInstrumentedType(), is((TypeDescription) typeDescription));
assertThat(methodRegistry.getInstrumentedMethods().size(), is(0)); assertThat(methodRegistry.getInstrumentedMethods().size(), is(0));
assertThat(methodRegistry.getTypeInitializer(), is(typeInitializer)); assertThat(methodRegistry.getTypeInitializer(), is(typeInitializer));
assertThat(methodRegistry.getLoadedTypeInitializer(), is(loadedTypeInitializer)); assertThat(methodRegistry.getLoadedTypeInitializer(), is(loadedTypeInitializer));
Expand Down
Expand Up @@ -90,7 +90,7 @@ public void testConstructor() throws Exception {
when(methodDescription.isConstructor()).thenReturn(true); when(methodDescription.isConstructor()).thenReturn(true);
when(superType.getDeclaredMethods()).thenReturn(superTypeMethods); when(superType.getDeclaredMethods()).thenReturn(superTypeMethods);
when(superTypeMethods.filter(any(ElementMatcher.class))).thenReturn(superTypeMethods); when(superTypeMethods.filter(any(ElementMatcher.class))).thenReturn(superTypeMethods);
when(implementationTarget.invokeSuper(methodToken)).thenReturn(Implementation.SpecialMethodInvocation.Illegal.INSTANCE); when(implementationTarget.invokeDominant(methodToken)).thenReturn(Implementation.SpecialMethodInvocation.Illegal.INSTANCE);
SuperMethodCall.INSTANCE.appender(implementationTarget).apply(methodVisitor, implementationContext, methodDescription); SuperMethodCall.INSTANCE.appender(implementationTarget).apply(methodVisitor, implementationContext, methodDescription);
} }


Expand All @@ -104,7 +104,7 @@ public void testStaticMethod() throws Exception {
when(returnType.getStackSize()).thenReturn(StackSize.SINGLE); when(returnType.getStackSize()).thenReturn(StackSize.SINGLE);
when(superType.getDeclaredMethods()).thenReturn(superTypeMethods); when(superType.getDeclaredMethods()).thenReturn(superTypeMethods);
when(superTypeMethods.filter(any(ElementMatcher.class))).thenReturn(superTypeMethods); when(superTypeMethods.filter(any(ElementMatcher.class))).thenReturn(superTypeMethods);
when(implementationTarget.invokeSuper(methodToken)).thenReturn(Implementation.SpecialMethodInvocation.Illegal.INSTANCE); when(implementationTarget.invokeDominant(methodToken)).thenReturn(Implementation.SpecialMethodInvocation.Illegal.INSTANCE);
SuperMethodCall.INSTANCE.appender(implementationTarget).apply(methodVisitor, implementationContext, methodDescription); SuperMethodCall.INSTANCE.appender(implementationTarget).apply(methodVisitor, implementationContext, methodDescription);
} }


Expand All @@ -119,7 +119,7 @@ public void testNoSuper() throws Exception {
when(returnType.getStackSize()).thenReturn(StackSize.SINGLE); when(returnType.getStackSize()).thenReturn(StackSize.SINGLE);
when(superType.getDeclaredMethods()).thenReturn(superTypeMethods); when(superType.getDeclaredMethods()).thenReturn(superTypeMethods);
when(superTypeMethods.filter(any(ElementMatcher.class))).thenReturn(superTypeMethods); when(superTypeMethods.filter(any(ElementMatcher.class))).thenReturn(superTypeMethods);
when(implementationTarget.invokeSuper(methodToken)).thenReturn(Implementation.SpecialMethodInvocation.Illegal.INSTANCE); when(implementationTarget.invokeDominant(methodToken)).thenReturn(Implementation.SpecialMethodInvocation.Illegal.INSTANCE);
SuperMethodCall.INSTANCE.appender(implementationTarget).apply(methodVisitor, implementationContext, methodDescription); SuperMethodCall.INSTANCE.appender(implementationTarget).apply(methodVisitor, implementationContext, methodDescription);
} }


Expand Down

0 comments on commit 6940d3b

Please sign in to comment.