use of net.bytebuddy.implementation.bytecode.constant.TextConstant in project byte-buddy by raphw.
the class MethodDelegationChainedTest method testChainingNonVoid.
@Test
public void testChainingNonVoid() throws Exception {
NonVoidInterceptor nonVoidInterceptor = new NonVoidInterceptor();
DynamicType.Loaded<Foo> dynamicType = new ByteBuddy().subclass(Foo.class).method(isDeclaredBy(Foo.class)).intercept(MethodDelegation.withDefaultConfiguration().filter(isDeclaredBy(NonVoidInterceptor.class)).to(nonVoidInterceptor).andThen(new Implementation.Simple(new TextConstant(FOO), MethodReturn.REFERENCE))).make().load(Foo.class.getClassLoader(), ClassLoadingStrategy.Default.WRAPPER);
assertThat(dynamicType.getLoaded().getDeclaredConstructor().newInstance().foo(), is(FOO));
assertThat(nonVoidInterceptor.intercepted, is(true));
}
use of net.bytebuddy.implementation.bytecode.constant.TextConstant in project byte-buddy by raphw.
the class MethodCallTest method testImplementationAppendingMethod.
@Test
public void testImplementationAppendingMethod() throws Exception {
DynamicType.Loaded<MethodCallAppending> loaded = new ByteBuddy().subclass(MethodCallAppending.class).method(isDeclaredBy(MethodCallAppending.class)).intercept(MethodCall.invokeSuper().andThen(new Implementation.Simple(new TextConstant(FOO), MethodReturn.REFERENCE))).make().load(MethodCallAppending.class.getClassLoader(), ClassLoadingStrategy.Default.WRAPPER);
assertThat(loaded.getLoadedAuxiliaryTypes().size(), is(0));
assertThat(loaded.getLoaded().getDeclaredMethods().length, is(1));
assertThat(loaded.getLoaded().getDeclaredMethod(FOO), not(nullValue(Method.class)));
assertThat(loaded.getLoaded().getDeclaredConstructors().length, is(1));
assertThat(loaded.getLoaded().getDeclaredFields().length, is(0));
MethodCallAppending instance = loaded.getLoaded().getDeclaredConstructor().newInstance();
assertThat(instance.getClass(), not(CoreMatchers.<Class<?>>is(MethodCallAppending.class)));
assertThat(instance, instanceOf(MethodCallAppending.class));
assertThat(instance.foo(), is((Object) FOO));
instance.assertOnlyCall(FOO);
}
use of net.bytebuddy.implementation.bytecode.constant.TextConstant in project byte-buddy by raphw.
the class SuperMethodCallOtherTest method testAndThen.
@Test
public void testAndThen() throws Exception {
DynamicType.Loaded<Foo> loaded = new ByteBuddy().subclass(Foo.class).method(isDeclaredBy(Foo.class)).intercept(SuperMethodCall.INSTANCE.andThen(new Implementation.Simple(new TextConstant(FOO), MethodReturn.REFERENCE))).make().load(Foo.class.getClassLoader(), ClassLoadingStrategy.Default.WRAPPER);
Foo foo = loaded.getLoaded().getDeclaredConstructor().newInstance();
assertThat(foo.foo(), is(FOO));
foo.assertOnlyCall(FOO);
}
Aggregations