use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.ByteBuddy in project byte-buddy by raphw.
the class MethodDelegationDefaultMethodTest method testExplicitDefaultCall.
@Test
@JavaVersionRule.Enforce(8)
public void testExplicitDefaultCall() 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(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) FOO));
}
use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.ByteBuddy in project byte-buddy by raphw.
the class MethodDelegationDefaultMethodTest 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 MethodDelegationDefaultTest method testDefaultInterface.
@Test
@JavaVersionRule.Enforce(8)
public void testDefaultInterface() throws Exception {
DynamicType.Loaded<?> loaded = new ByteBuddy().subclass(Object.class).implement(Class.forName(DEFAULT_INTERFACE)).intercept(MethodDelegation.to(Class.forName(DELEGATION_TARGET))).make().load(Class.forName(DEFAULT_INTERFACE).getClassLoader(), ClassLoadingStrategy.Default.WRAPPER);
Object instance = loaded.getLoaded().getDeclaredConstructor().newInstance();
assertThat(instance.getClass().getDeclaredMethod(FOO).invoke(instance), is((Object) (FOO + BAR)));
}
use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.ByteBuddy in project byte-buddy by raphw.
the class MethodDelegationFieldProxyTest method testIncompatibleTypeThrowsExceptionSetDuplex.
@Test(expected = ClassCastException.class)
public void testIncompatibleTypeThrowsExceptionSetDuplex() throws Exception {
DynamicType.Loaded<Explicit> loaded = new ByteBuddy().subclass(Explicit.class).method(isDeclaredBy(Explicit.class)).intercept(MethodDelegation.withDefaultConfiguration().withBinders(FieldProxy.Binder.install(GetSet.class)).to(SetterIncompatibleDuplex.class)).make().load(Explicit.class.getClassLoader(), ClassLoadingStrategy.Default.WRAPPER);
Explicit explicit = loaded.getLoaded().getDeclaredConstructor().newInstance();
explicit.swap();
}
use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.ByteBuddy in project byte-buddy by raphw.
the class MethodDelegationFieldProxyTest method testExplicitFieldAccessStatic.
@Test
public void testExplicitFieldAccessStatic() throws Exception {
DynamicType.Loaded<ExplicitStatic> loaded = new ByteBuddy().subclass(ExplicitStatic.class).method(isDeclaredBy(ExplicitStatic.class)).intercept(MethodDelegation.withDefaultConfiguration().withBinders(FieldProxy.Binder.install(Get.class, Set.class)).to(Swap.class)).make().load(ExplicitStatic.class.getClassLoader(), ClassLoadingStrategy.Default.WRAPPER);
ExplicitStatic explicit = loaded.getLoaded().getDeclaredConstructor().newInstance();
assertThat(ExplicitStatic.foo, is(FOO));
explicit.swap();
assertThat(ExplicitStatic.foo, is(FOO + BAR));
}
Aggregations