@Test public void testSerializableProxy() throws Exception { DynamicType.Loaded<Foo> loaded = instrument(Foo.class, MethodDelegation.to(SerializationCheck.class)); Foo instance = loaded.getLoaded().newInstance(); assertThat(instance.qux(), is((Object) (FOO + QUX))); }
@Test public void testIncludeSelf() throws Exception { DynamicType.Loaded<Qux> loaded = new ByteBuddy() .subclass(Qux.class) .method(isDeclaredBy(Qux.class)) .intercept(MethodDelegation.to(IncludeSelf.class)) .make() .load(Foo.class.getClassLoader(), ClassLoadingStrategy.Default.WRAPPER); Qux instance = loaded.getLoaded().getDeclaredConstructor().newInstance(); assertThat(instance.foo(QUX, BAZ), is((Object) instance)); }
@Test public void testStrictBindable() throws Exception { DynamicType.Loaded<Foo> loaded = new ByteBuddy() .subclass(Foo.class) .method(isDeclaredBy(Foo.class)) .intercept(MethodDelegation.to(Bar.class)) .make() .load(Foo.class.getClassLoader(), ClassLoadingStrategy.Default.WRAPPER); Foo instance = loaded.getLoaded().getDeclaredConstructor().newInstance(); assertThat(instance.foo(FOO, BAR), is((Object) (QUX + FOO + BAR))); }
@Test public void testThis() throws Exception { DynamicType.Loaded<Foo> loaded = implement(Foo.class, MethodDelegation.to(Bar.class)); Foo instance = loaded.getLoaded().newInstance(); assertThat(instance.foo(), is((Object) instance)); }
@Test(expected = AbstractMethodError.class) public void testSuperCallOnAbstractMethod() throws Exception { DynamicType.Loaded<FooBarQuxBaz> loaded = instrument(FooBarQuxBaz.class, MethodDelegation.to(FooBar.class)); loaded.getLoaded().newInstance().qux(); }
@Test public void testBridgeMethodResolution() throws Exception { DynamicType.Loaded<Bar> loaded = instrument(Bar.class, MethodDelegation.to(GenericBaz.class)); Bar instance = loaded.getLoaded().newInstance(); assertThat(instance.qux(BAR), is(BAR + QUX)); }
@Test public void testSuperInstanceUnsafe() throws Exception { DynamicType.Loaded<Foo> loaded = instrument(Foo.class, MethodDelegation.to(QuxBaz.class)); Foo instance = loaded.getLoaded().newInstance(); assertThat(instance.qux(), is((Object) (FOO + QUX))); }