コード例 #1
0
 @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)));
 }
コード例 #2
0
 @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));
 }
コード例 #3
0
 @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)));
 }
コード例 #4
0
 @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));
 }
コード例 #5
0
 @Test(expected = AbstractMethodError.class)
 public void testSuperCallOnAbstractMethod() throws Exception {
   DynamicType.Loaded<FooBarQuxBaz> loaded =
       instrument(FooBarQuxBaz.class, MethodDelegation.to(FooBar.class));
   loaded.getLoaded().newInstance().qux();
 }
コード例 #6
0
 @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));
 }
コード例 #7
0
 @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)));
 }