use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.ByteBuddy in project byte-buddy by raphw.
the class MethodCallTest method testSuperInvocation.
@Test
public void testSuperInvocation() throws Exception {
DynamicType.Loaded<SuperMethodInvocation> loaded = new ByteBuddy().subclass(SuperMethodInvocation.class).method(takesArguments(0).and(named(FOO))).intercept(MethodCall.invokeSuper()).make().load(SuperMethodInvocation.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));
SuperMethodInvocation instance = loaded.getLoaded().getDeclaredConstructor().newInstance();
assertThat(instance.getClass(), not(CoreMatchers.<Class<?>>is(SuperMethodInvocation.class)));
assertThat(instance, instanceOf(SuperMethodInvocation.class));
assertThat(instance.foo(), is(FOO));
}
use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.ByteBuddy in project byte-buddy by raphw.
the class MethodCallTest method testInvokeOnArgumentDynamic.
@Test
public void testInvokeOnArgumentDynamic() throws Exception {
DynamicType.Loaded<ArgumentCallDynamic> loaded = new ByteBuddy().subclass(ArgumentCallDynamic.class).method(isDeclaredBy(ArgumentCallDynamic.class)).intercept(MethodCall.invoke(ArgumentCallDynamic.Target.class.getDeclaredMethod("foo")).onArgument(0).withAssigner(Assigner.DEFAULT, Assigner.Typing.DYNAMIC)).make().load(ArgumentCallDynamic.class.getClassLoader(), ClassLoadingStrategy.Default.WRAPPER);
assertThat(loaded.getLoadedAuxiliaryTypes().size(), is(0));
assertThat(loaded.getLoaded().getDeclaredMethods().length, is(1));
assertThat(loaded.getLoaded().getDeclaredFields().length, is(0));
ArgumentCallDynamic instance = loaded.getLoaded().getDeclaredConstructor().newInstance();
assertThat(instance.foo(new ArgumentCallDynamic.Target(BAR)), is(BAR));
assertThat(instance.getClass(), not(CoreMatchers.<Class<?>>is(InstanceMethod.class)));
assertThat(instance, instanceOf(ArgumentCallDynamic.class));
}
use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.ByteBuddy in project byte-buddy by raphw.
the class MethodDelegationDefaultCallTest method testSerializableProxy.
@Test
@JavaVersionRule.Enforce(8)
public void testSerializableProxy() throws Exception {
DynamicType.Loaded<?> loaded = new ByteBuddy().subclass(Object.class).implement(Class.forName(SINGLE_DEFAULT_METHOD)).intercept(MethodDelegation.to(SerializationCheck.class)).make().load(Class.forName(SINGLE_DEFAULT_METHOD).getClassLoader(), ClassLoadingStrategy.Default.WRAPPER);
Object instance = loaded.getLoaded().getDeclaredConstructor().newInstance();
Method method = loaded.getLoaded().getMethod(FOO);
assertThat(method.invoke(instance), is((Object) FOO));
}
use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.ByteBuddy in project byte-buddy by raphw.
the class MethodDelegationDefaultCallTest method testExplicitDefaultCallToOtherInterface.
@Test
@JavaVersionRule.Enforce(8)
public void testExplicitDefaultCallToOtherInterface() throws Exception {
DynamicType.Loaded<?> loaded = new ByteBuddy().subclass(Object.class).implement(Class.forName(SINGLE_DEFAULT_METHOD), Class.forName(CONFLICTING_INTERFACE)).intercept(MethodDelegation.to(Class.forName(CONFLICTING_PREFERRING_INTERCEPTOR))).make().load(getClass().getClassLoader(), ClassLoadingStrategy.Default.WRAPPER);
Object instance = loaded.getLoaded().getDeclaredConstructor().newInstance();
Method method = loaded.getLoaded().getMethod(FOO);
assertThat(method.invoke(instance), is((Object) QUX));
}
use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.ByteBuddy in project byte-buddy by raphw.
the class MethodDelegationDefaultMethodTest method testCallableDefaultCall.
@Test
@JavaVersionRule.Enforce(8)
public void testCallableDefaultCall() throws Exception {
DynamicType.Loaded<?> loaded = new ByteBuddy().subclass(Object.class).implement(Class.forName(SINGLE_DEFAULT_METHOD)).intercept(MethodDelegation.to(SampleClass.class)).make().load(Class.forName(SINGLE_DEFAULT_METHOD).getClassLoader(), ClassLoadingStrategy.Default.WRAPPER);
Object instance = loaded.getLoaded().getDeclaredConstructor().newInstance();
Method method = loaded.getLoaded().getMethod(FOO);
assertThat(method.invoke(instance), is((Object) FOO));
}
Aggregations