use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.dynamic.DynamicType in project byte-buddy by raphw.
the class MethodDelegationChainedTest method testChainingVoid.
@Test
public void testChainingVoid() throws Exception {
VoidInterceptor voidInterceptor = new VoidInterceptor();
DynamicType.Loaded<Foo> dynamicType = new ByteBuddy().subclass(Foo.class).method(isDeclaredBy(Foo.class)).intercept(MethodDelegation.withDefaultConfiguration().filter(isDeclaredBy(VoidInterceptor.class)).to(voidInterceptor).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(voidInterceptor.intercepted, is(true));
}
use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.dynamic.DynamicType 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 org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.dynamic.DynamicType in project byte-buddy by raphw.
the class InvokeDynamicTest method testBootstrapWithThisValue.
@Test
@JavaVersionRule.Enforce(7)
public void testBootstrapWithThisValue() throws Exception {
TypeDescription typeDescription = new TypeDescription.ForLoadedType(Class.forName(ARGUMENT_BOOTSTRAP));
DynamicType.Loaded<Simple> dynamicType = new ByteBuddy().subclass(Simple.class).method(isDeclaredBy(Simple.class)).intercept(InvokeDynamic.bootstrap(typeDescription.getDeclaredMethods().filter(named(BOOTSTRAP)).getOnly()).invoke(BAZ, String.class).withThis(Object.class)).make().load(getClass().getClassLoader(), ClassLoadingStrategy.Default.WRAPPER);
assertThat(dynamicType.getLoaded().getDeclaredFields().length, is(0));
Simple simple = dynamicType.getLoaded().getDeclaredConstructor().newInstance();
assertThat(simple.foo(), is(simple.toString()));
}
use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.dynamic.DynamicType in project byte-buddy by raphw.
the class InvokeDynamicTest method testBootstrapMethod.
@Test
@JavaVersionRule.Enforce(7)
public void testBootstrapMethod() throws Exception {
for (Method method : Class.forName(STANDARD_ARGUMENT_BOOTSTRAP).getDeclaredMethods()) {
if (method.getName().equals(FOO)) {
continue;
}
DynamicType.Loaded<Simple> dynamicType = new ByteBuddy().subclass(Simple.class).method(isDeclaredBy(Simple.class)).intercept(InvokeDynamic.bootstrap(method).withoutArguments()).make().load(getClass().getClassLoader(), ClassLoadingStrategy.Default.WRAPPER);
assertThat(dynamicType.getLoaded().getDeclaredConstructor().newInstance().foo(), is(FOO));
}
}
use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.dynamic.DynamicType in project byte-buddy by raphw.
the class InvokeDynamicTest method testBootstrapWithArgument.
@Test
@JavaVersionRule.Enforce(7)
public void testBootstrapWithArgument() throws Exception {
TypeDescription typeDescription = new TypeDescription.ForLoadedType(Class.forName(ARGUMENT_BOOTSTRAP));
DynamicType.Loaded<SimpleWithArgument> dynamicType = new ByteBuddy().subclass(SimpleWithArgument.class).method(isDeclaredBy(SimpleWithArgument.class)).intercept(InvokeDynamic.bootstrap(typeDescription.getDeclaredMethods().filter(named(BOOTSTRAP)).getOnly()).invoke(QUX, String.class).withArgument(0)).make().load(getClass().getClassLoader(), ClassLoadingStrategy.Default.WRAPPER);
assertThat(dynamicType.getLoaded().getDeclaredFields().length, is(0));
assertThat(dynamicType.getLoaded().getDeclaredConstructor().newInstance().foo(FOO), is(FOO));
}
Aggregations