Skip to content

Commit 54165f2

Browse files
committed
Add test for method call in substitution chain.
1 parent 71c3dce commit 54165f2

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

byte-buddy-dep/src/test/java/net/bytebuddy/asm/MemberSubstitutionTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -978,6 +978,24 @@ public void testSubstitutionChainMethodInvocation() throws Exception {
978978
assertThat(type.getDeclaredField(BAR).get(instance), is((Object) BAZ));
979979
}
980980

981+
@Test
982+
public void testSubstitutionChainMethodInvocationWithArgument() throws Exception {
983+
Class<?> type = new ByteBuddy()
984+
.redefine(StaticMethodInvokeSample.class)
985+
.visit(MemberSubstitution.strict().method(named(BAR)).replaceWithChain(
986+
new MemberSubstitution.Substitution.Chain.Step.ForInvocation.Factory(
987+
StaticMethodInvokeSample.class.getDeclaredMethod(BAZ, String.class))).on(named(RUN)))
988+
.make()
989+
.load(ClassLoadingStrategy.BOOTSTRAP_LOADER, ClassLoadingStrategy.Default.WRAPPER)
990+
.getLoaded();
991+
Object instance = type.getDeclaredConstructor().newInstance();
992+
assertThat(type.getDeclaredField(BAR).get(instance), is((Object) BAR));
993+
assertThat(type.getDeclaredField(BAZ).get(instance), is((Object) BAZ));
994+
assertThat(type.getDeclaredMethod(RUN).invoke(instance), nullValue(Object.class));
995+
assertThat(type.getDeclaredField(BAR).get(instance), is((Object) BAR));
996+
assertThat(type.getDeclaredField(BAZ).get(instance), is((Object) FOO));
997+
}
998+
981999
@Test
9821000
public void testSubstitutionChainStaticMethodInvocation() throws Exception {
9831001
Class<?> type = new ByteBuddy()

0 commit comments

Comments
 (0)