use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.ByteBuddy in project byte-buddy by raphw.
the class AdviceTest method testAdviceWithOptionalThisReferenceOptional.
@Test
public void testAdviceWithOptionalThisReferenceOptional() throws Exception {
Class<?> type = new ByteBuddy().redefine(Sample.class).visit(Advice.to(OptionalThisReferenceAdvice.class).on(named(BAZ))).make().load(ClassLoadingStrategy.BOOTSTRAP_LOADER, ClassLoadingStrategy.Default.WRAPPER).getLoaded();
assertThat(type.getDeclaredMethod(BAZ).invoke(null), is((Object) FOO));
assertThat(type.getDeclaredField(ENTER).get(null), is((Object) 1));
assertThat(type.getDeclaredField(EXIT).get(null), is((Object) 1));
}
use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.ByteBuddy in project byte-buddy by raphw.
the class AdviceTest method testOriginConstructorAdvice.
@Test
public void testOriginConstructorAdvice() throws Exception {
Class<?> type = new ByteBuddy().redefine(Sample.class).visit(Advice.to(OriginConstructorAdvice.class).on(isConstructor())).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));
}
use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.ByteBuddy in project byte-buddy by raphw.
the class AdviceTest method testEmptyAdviceEntryAndExitWithExceptionHandlingAndEntrySuppression.
@Test
public void testEmptyAdviceEntryAndExitWithExceptionHandlingAndEntrySuppression() throws Exception {
Class<?> type = new ByteBuddy().redefine(EmptyMethod.class).visit(Advice.to(EmptyAdviceWithExceptionHandlingAndEntrySuppression.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 testLineNumberNoPrependDelegation.
@Test
public void testLineNumberNoPrependDelegation() throws Exception {
Class<?> type = new ByteBuddy().redefine(NoLineNumberDelegatingAdvice.class).visit(Advice.to(NoLineNumberDelegatingAdvice.class).on(named(FOO))).make().load(ClassLoadingStrategy.BOOTSTRAP_LOADER, ClassLoadingStrategy.Default.WRAPPER).getLoaded();
assertThat(type.getDeclaredMethod(FOO).invoke(type.getDeclaredConstructor().newInstance()), is((Object) FOO));
}
use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.ByteBuddy in project byte-buddy by raphw.
the class AdviceTest method testTrivialAdviceWithSuppression.
@Test
public void testTrivialAdviceWithSuppression() throws Exception {
Class<?> type = new ByteBuddy().redefine(Sample.class).visit(Advice.to(TrivialAdviceWithSuppression.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