use of net.bytebuddy.ByteBuddy in project byte-buddy by raphw.
the class AdviceExchangedDuplicationTest method testAdvice.
@Test
public void testAdvice() throws Exception {
Class<?> type = new ByteBuddy().subclass(Object.class).defineMethod(FOO, valueType, Visibility.PUBLIC).intercept(new DuplicationImplementation()).make().load(getClass().getClassLoader(), ClassLoadingStrategy.Default.WRAPPER_PERSISTENT).getLoaded();
Class<?> redefined = new ByteBuddy().redefine(type).visit(Advice.to(AdviceExchangedDuplicationTest.class).on(named(FOO))).make().load(ClassLoadingStrategy.BOOTSTRAP_LOADER, ClassLoadingStrategy.Default.WRAPPER).getLoaded();
assertThat(redefined.getDeclaredMethod(FOO).invoke(redefined.getDeclaredConstructor().newInstance()), is(value));
}
use of net.bytebuddy.ByteBuddy in project byte-buddy by raphw.
the class AdviceFrameTest method testFrameAdviceExpanded.
@Test
public void testFrameAdviceExpanded() throws Exception {
Class<?> type = new ByteBuddy().redefine(FrameSample.class).visit(Advice.to(advice).on(named(FOO)).readerFlags(ClassReader.EXPAND_FRAMES)).make().load(ClassLoadingStrategy.BOOTSTRAP_LOADER, ClassLoadingStrategy.Default.WRAPPER).getLoaded();
assertThat(type.getDeclaredMethod(FOO, String.class).invoke(type.getDeclaredConstructor().newInstance(), FOO), is((Object) FOO));
assertThat(type.getField(COUNT).getInt(null), is((Object) count));
}
use of net.bytebuddy.ByteBuddy in project byte-buddy by raphw.
the class AdviceFrameTest method testFrameAdviceComputedMaxima.
@Test
public void testFrameAdviceComputedMaxima() throws Exception {
Class<?> type = new ByteBuddy().redefine(FrameSample.class).visit(Advice.to(advice).on(named(FOO)).writerFlags(ClassWriter.COMPUTE_MAXS)).make().load(ClassLoadingStrategy.BOOTSTRAP_LOADER, ClassLoadingStrategy.Default.WRAPPER).getLoaded();
assertThat(type.getDeclaredMethod(FOO, String.class).invoke(type.getDeclaredConstructor().newInstance(), FOO), is((Object) FOO));
assertThat(type.getField(COUNT).getInt(null), is((Object) count));
}
use of net.bytebuddy.ByteBuddy in project byte-buddy by raphw.
the class AdviceFrameTest method testFrameAdviceStaticMethodComputedMaxima.
@Test
public void testFrameAdviceStaticMethodComputedMaxima() throws Exception {
Class<?> type = new ByteBuddy().redefine(FrameSample.class).visit(Advice.to(advice).on(named(BAR)).writerFlags(ClassWriter.COMPUTE_MAXS)).make().load(ClassLoadingStrategy.BOOTSTRAP_LOADER, ClassLoadingStrategy.Default.WRAPPER).getLoaded();
assertThat(type.getDeclaredMethod(BAR, String.class).invoke(null, FOO), is((Object) FOO));
assertThat(type.getField(COUNT).getInt(null), is((Object) count));
}
use of net.bytebuddy.ByteBuddy in project byte-buddy by raphw.
the class AdviceFrameTest method testFrameAdviceStaticMethod.
@Test
public void testFrameAdviceStaticMethod() throws Exception {
Class<?> type = new ByteBuddy().redefine(FrameSample.class).visit(Advice.to(advice).on(named(BAR))).make().load(ClassLoadingStrategy.BOOTSTRAP_LOADER, ClassLoadingStrategy.Default.WRAPPER).getLoaded();
assertThat(type.getDeclaredMethod(BAR, String.class).invoke(null, FOO), is((Object) FOO));
assertThat(type.getField(COUNT).getInt(null), is((Object) count));
}
Aggregations