use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.ByteBuddy in project byte-buddy by raphw.
the class AdviceNoRegularReturnWithinAdviceTest method testNoRegularReturn.
@Test
public void testNoRegularReturn() throws Exception {
Class<?> type = new ByteBuddy().redefine(Sample.class).visit(Advice.to(this.type).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));
}
}
use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.ByteBuddy in project byte-buddy by raphw.
the class AdviceSizeConversionTest method testAdvice.
@Test
public void testAdvice() throws Exception {
Class<?> type = new ByteBuddy().redefine(target).visit(Advice.to(AdviceSizeConversionTest.class).on(named(FOO))).make().load(ClassLoadingStrategy.BOOTSTRAP_LOADER, ClassLoadingStrategy.Default.WRAPPER).getLoaded();
assertThat(type.getDeclaredMethod(FOO, parameter).invoke(type.getDeclaredConstructor().newInstance(), input), is(output));
}
use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.ByteBuddy in project byte-buddy by raphw.
the class AdviceSkipOnDefaultValueTest method testAdvice.
@Test
public void testAdvice() throws Exception {
Class<?> type = new ByteBuddy().redefine(this.type).visit(Advice.to(this.type).on(named(FOO))).make().load(ClassLoadingStrategy.BOOTSTRAP_LOADER, ClassLoadingStrategy.Default.WRAPPER).getLoaded();
assertThat(type.getDeclaredMethod(FOO).invoke(type.getDeclaredConstructor().newInstance()), is(value));
}
use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.ByteBuddy in project byte-buddy by raphw.
the class AdviceCustomAnnotationOnFieldTest method testPrimitiveField.
@Test
public void testPrimitiveField() throws Exception {
Class<?> type = new ByteBuddy().redefine(target).visit(Advice.withCustomMapping().bind(FieldValue.class, new FieldDescription.ForLoadedField(target.getDeclaredField(FOO))).to(target).on(named(FOO))).make().load(ClassLoadingStrategy.BOOTSTRAP_LOADER, ClassLoadingStrategy.Default.WRAPPER).getLoaded();
assertThat(type.getDeclaredMethod(FOO).invoke(type.getDeclaredConstructor().newInstance()), is(expected));
}
use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.ByteBuddy in project byte-buddy by raphw.
the class AdviceDeadCodeTest method testAdviceContainsDeadCode.
@Test
public void testAdviceContainsDeadCode() throws Exception {
Class<?> advice = new ByteBuddy(classFileVersion).subclass(Object.class).defineMethod(FOO, void.class, Ownership.STATIC).intercept(new DeadVoidAppender()).annotateMethod(AnnotationDescription.Builder.ofType(Advice.OnMethodEnter.class).define("suppress", RuntimeException.class).build()).annotateMethod(AnnotationDescription.Builder.ofType(Advice.OnMethodExit.class).define("suppress", RuntimeException.class).build()).make().load(getClass().getClassLoader(), ClassLoadingStrategy.Default.WRAPPER_PERSISTENT).getLoaded();
Class<?> foo = new ByteBuddy(classFileVersion).subclass(Object.class).defineMethod("foo", String.class, Visibility.PUBLIC).intercept(FixedValue.value(FOO)).make().load(ClassLoadingStrategy.BOOTSTRAP_LOADER, ClassLoadingStrategy.Default.WRAPPER_PERSISTENT).getLoaded();
Class<?> redefined = new ByteBuddy().redefine(foo).visit(Advice.to(advice).on(named(FOO))).make().load(null, ClassLoadingStrategy.Default.CHILD_FIRST).getLoaded();
assertThat(redefined, not(sameInstance((Object) foo)));
assertThat(redefined.getDeclaredMethod(FOO).invoke(redefined.getDeclaredConstructor().newInstance()), is((Object) FOO));
}
Aggregations