use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.ByteBuddy in project byte-buddy by raphw.
the class AdviceTest method testEmptyAdviceExit.
@Test
public void testEmptyAdviceExit() throws Exception {
Class<?> type = new ByteBuddy().redefine(EmptyMethod.class).visit(Advice.to(EmptyAdviceExit.class).on(named(FOO)).readerFlags(ClassReader.SKIP_DEBUG)).make().load(ClassLoadingStrategy.BOOTSTRAP_LOADER, ClassLoadingStrategy.Default.WRAPPER).getLoaded();
assertThat(type.getDeclaredMethod(FOO).invoke(type.getDeclaredConstructor().newInstance()), nullValue(Object.class));
}
use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.ByteBuddy in project byte-buddy by raphw.
the class AdviceTest method testThisValueSubstitution.
@Test
public void testThisValueSubstitution() throws Exception {
Class<?> type = new ByteBuddy().redefine(Box.class).visit(Advice.to(ThisSubstitutionAdvice.class).on(named(FOO))).make().load(ClassLoadingStrategy.BOOTSTRAP_LOADER, ClassLoadingStrategy.Default.WRAPPER).getLoaded();
assertThat(type.getDeclaredMethod(FOO).invoke(type.getDeclaredConstructor(String.class).newInstance(FOO)), is((Object) BAR));
}
use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.ByteBuddy in project byte-buddy by raphw.
the class AdviceTest method testAdviceThrowOnEnter.
@Test
public void testAdviceThrowOnEnter() throws Exception {
Class<?> type = new ByteBuddy().redefine(TracableSample.class).visit(Advice.to(ThrowOnEnter.class).on(named(FOO))).make().load(ClassLoadingStrategy.BOOTSTRAP_LOADER, ClassLoadingStrategy.Default.WRAPPER).getLoaded();
try {
type.getDeclaredMethod(FOO).invoke(type.getDeclaredConstructor().newInstance());
fail();
} catch (InvocationTargetException exception) {
assertThat(exception.getCause(), instanceOf(RuntimeException.class));
}
assertThat(type.getDeclaredField(ENTER).get(null), is((Object) 1));
assertThat(type.getDeclaredField(INSIDE).get(null), is((Object) 0));
assertThat(type.getDeclaredField(EXIT).get(null), is((Object) 0));
}
use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.ByteBuddy in project byte-buddy by raphw.
the class AdviceTest method testAdviceWithImplicitArgumentDelegation.
@Test
public void testAdviceWithImplicitArgumentDelegation() throws Exception {
Class<?> type = new ByteBuddy().redefine(ArgumentAdviceDelegationImplicit.class).visit(Advice.to(ArgumentAdviceDelegationImplicit.class).on(named(FOO))).make().load(ClassLoadingStrategy.BOOTSTRAP_LOADER, ClassLoadingStrategy.Default.WRAPPER).getLoaded();
assertThat(type.getDeclaredMethod(FOO, String.class).invoke(type.getDeclaredConstructor().newInstance(), BAR), is((Object) BAR));
}
use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.ByteBuddy in project byte-buddy by raphw.
the class AdviceTest method testAdviceSkipExceptionDoesNotSkipNonException.
@Test
public void testAdviceSkipExceptionDoesNotSkipNonException() throws Exception {
Class<?> type = new ByteBuddy().redefine(Sample.class).visit(Advice.to(TrivialAdviceSkipException.class).on(named(FOO))).make().load(ClassLoadingStrategy.BOOTSTRAP_LOADER, ClassLoadingStrategy.Default.WRAPPER).getLoaded();
assertThat(type.getDeclaredMethod(FOO).invoke(type.getDeclaredConstructor().newInstance()), is((Object) FOO));
assertThat(type.getDeclaredField(ENTER).get(null), is((Object) 1));
assertThat(type.getDeclaredField(EXIT).get(null), is((Object) 1));
}
Aggregations