use of net.bytebuddy.ByteBuddy in project byte-buddy by raphw.
the class AdviceTest method testInstanceOfSkip.
@Test
public void testInstanceOfSkip() throws Exception {
Class<?> type = new ByteBuddy().redefine(InstanceOfSkip.class).visit(Advice.to(InstanceOfSkip.class).on(named(FOO))).make().load(ClassLoadingStrategy.BOOTSTRAP_LOADER, ClassLoadingStrategy.Default.WRAPPER).getLoaded();
assertThat(type.getDeclaredMethod(FOO).invoke(type.getDeclaredConstructor().newInstance()), nullValue(Object.class));
}
use of net.bytebuddy.ByteBuddy in project byte-buddy by raphw.
the class AdviceTest method testVariableMappingInstrumentedLarger.
@Test
public void testVariableMappingInstrumentedLarger() throws Exception {
Class<?> type = new ByteBuddy().redefine(Sample.class).visit(Advice.to(AdviceWithVariableValues.class).on(named(QUX + BAZ))).make().load(ClassLoadingStrategy.BOOTSTRAP_LOADER, ClassLoadingStrategy.Default.WRAPPER).getLoaded();
assertThat(type.getDeclaredMethod(QUX + BAZ).invoke(type.getDeclaredConstructor().newInstance()), is((Object) (FOO + BAR + QUX + BAZ)));
assertThat(type.getDeclaredField(ENTER).get(null), is((Object) 1));
assertThat(type.getDeclaredField(EXIT).get(null), is((Object) 1));
}
use of net.bytebuddy.ByteBuddy in project byte-buddy by raphw.
the class AdviceTest method testEmptyAdviceExitWithExceptionHandling.
@Test
public void testEmptyAdviceExitWithExceptionHandling() throws Exception {
Class<?> type = new ByteBuddy().redefine(EmptyMethod.class).visit(Advice.to(EmptyAdviceExitWithExceptionHandling.class).on(named(FOO))).make().load(ClassLoadingStrategy.BOOTSTRAP_LOADER, ClassLoadingStrategy.Default.WRAPPER).getLoaded();
assertThat(type.getDeclaredMethod(FOO).invoke(type.getDeclaredConstructor().newInstance()), nullValue(Object.class));
}
use of net.bytebuddy.ByteBuddy in project byte-buddy by raphw.
the class AdviceTest method testEmptyAdviceEntryAndExitWithSuppression.
@Test
public void testEmptyAdviceEntryAndExitWithSuppression() throws Exception {
Class<?> type = new ByteBuddy().redefine(EmptyMethod.class).visit(Advice.to(EmptyAdviceWithSuppression.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 net.bytebuddy.ByteBuddy in project byte-buddy by raphw.
the class AdviceTest method testFieldAdviceExplicit.
@Test
public void testFieldAdviceExplicit() throws Exception {
Class<?> type = new ByteBuddy().redefine(FieldSample.class).visit(Advice.to(FieldAdviceExplicit.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