use of 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));
}
use of net.bytebuddy.ByteBuddy in project byte-buddy by raphw.
the class AdviceTest method testAdviceThrowSuppressed.
@Test
public void testAdviceThrowSuppressed() throws Exception {
Class<?> type = new ByteBuddy().redefine(TracableSample.class).visit(Advice.to(ThrowSuppressed.class).on(named(FOO))).make().load(ClassLoadingStrategy.BOOTSTRAP_LOADER, ClassLoadingStrategy.Default.WRAPPER).getLoaded();
type.getDeclaredMethod(FOO).invoke(type.getDeclaredConstructor().newInstance());
assertThat(type.getDeclaredField(ENTER).get(null), is((Object) 1));
assertThat(type.getDeclaredField(INSIDE).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 testUserUnloadedTypeValue.
@Test
public void testUserUnloadedTypeValue() throws Exception {
Class<?> type = new ByteBuddy().redefine(Sample.class).visit(Advice.withCustomMapping().bind(Custom.class, TypeDescription.OBJECT).to(CustomAdvice.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 net.bytebuddy.ByteBuddy in project byte-buddy by raphw.
the class AdviceTest method testPrimitiveNonAssignableCasting.
@Test
public void testPrimitiveNonAssignableCasting() throws Exception {
Class<?> type = new ByteBuddy().redefine(NonAssignablePrimitiveReturnTypeAdvice.class).visit(Advice.to(NonAssignablePrimitiveReturnTypeAdvice.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(ClassCastException.class));
}
}
use of net.bytebuddy.ByteBuddy in project byte-buddy by raphw.
the class AdviceTest method testLineNumberNoPrepend.
@Test
public void testLineNumberNoPrepend() throws Exception {
Class<?> type = new ByteBuddy().redefine(Sample.class).visit(Advice.to(NoLineNumberAdvice.class).on(named(FOO))).make().load(ClassLoadingStrategy.BOOTSTRAP_LOADER, ClassLoadingStrategy.Default.WRAPPER).getLoaded();
assertThat(type.getDeclaredMethod(FOO).invoke(type.getDeclaredConstructor().newInstance()), is((Object) FOO));
}
Aggregations