Skip to content

Commit

Permalink
Add test for method call in substitution chain.
Browse files Browse the repository at this point in the history
  • Loading branch information
raphw committed Feb 8, 2025
1 parent 71c3dce commit 54165f2
Showing 1 changed file with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -978,6 +978,24 @@ public void testSubstitutionChainMethodInvocation() throws Exception {
assertThat(type.getDeclaredField(BAR).get(instance), is((Object) BAZ));
}

@Test
public void testSubstitutionChainMethodInvocationWithArgument() throws Exception {
Class<?> type = new ByteBuddy()
.redefine(StaticMethodInvokeSample.class)
.visit(MemberSubstitution.strict().method(named(BAR)).replaceWithChain(
new MemberSubstitution.Substitution.Chain.Step.ForInvocation.Factory(
StaticMethodInvokeSample.class.getDeclaredMethod(BAZ, String.class))).on(named(RUN)))
.make()
.load(ClassLoadingStrategy.BOOTSTRAP_LOADER, ClassLoadingStrategy.Default.WRAPPER)
.getLoaded();
Object instance = type.getDeclaredConstructor().newInstance();
assertThat(type.getDeclaredField(BAR).get(instance), is((Object) BAR));
assertThat(type.getDeclaredField(BAZ).get(instance), is((Object) BAZ));
assertThat(type.getDeclaredMethod(RUN).invoke(instance), nullValue(Object.class));
assertThat(type.getDeclaredField(BAR).get(instance), is((Object) BAR));
assertThat(type.getDeclaredField(BAZ).get(instance), is((Object) FOO));
}

@Test
public void testSubstitutionChainStaticMethodInvocation() throws Exception {
Class<?> type = new ByteBuddy()
Expand Down

0 comments on commit 54165f2

Please sign in to comment.