@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)); }
public static String baz(@Super Qux foo) { assertThat(foo, not(instanceOf(Serializable.class))); return foo.qux() + QUX; }