@Test public void testStaticAdapterWithMethodCache() throws Exception { Foo foo = new Foo(); DynamicType.Loaded<Bar> loaded = new ByteBuddy() .subclass(Bar.class) .method(isDeclaredBy(Bar.class)) .intercept(InvocationHandlerAdapter.of(foo)) .make() .load(Bar.class.getClassLoader(), ClassLoadingStrategy.Default.WRAPPER); assertThat(loaded.getLoadedAuxiliaryTypes().size(), is(0)); assertThat(loaded.getLoaded().getDeclaredMethods().length, is(1)); assertThat(loaded.getLoaded().getDeclaredFields().length, is(2)); Bar instance = loaded.getLoaded().getDeclaredConstructor().newInstance(); assertThat(instance.bar(FOO), is((Object) instance)); assertThat(foo.methods.size(), is(1)); assertThat(instance.bar(FOO), is((Object) instance)); assertThat(foo.methods.size(), is(2)); assertThat(foo.methods.get(0), sameInstance(foo.methods.get(1))); instance.assertZeroCalls(); }
public static InvocationHandlerAdapter of(InvocationHandler invocationHandler) { return of(invocationHandler, ForInstance.PREFIX + "$" + RandomString.hashOf(invocationHandler.hashCode())); }
InvocationHandlerAdapter implements Implementation { public static InvocationHandlerAdapter of(InvocationHandler invocationHandler) { return of(invocationHandler, ForInstance.PREFIX + "$" + RandomString.hashOf(invocationHandler.hashCode())); } }
InvocationHandlerAdapter implements Implementation { public static InvocationHandlerAdapter of(InvocationHandler invocationHandler) { return of(invocationHandler, ForInstance.PREFIX + "$" + RandomString.hashOf(invocationHandler.hashCode())); } protected  InvocationHandlerAdapter(String fieldName, boolean cached, boolean privileged, Assigner assigner); }
InvocationHandlerAdapter implements Implementation { public static InvocationHandlerAdapter of(InvocationHandler invocationHandler) { return of(invocationHandler, ForInstance.PREFIX + "$" + RandomString.hashOf(invocationHandler.hashCode())); } protected  InvocationHandlerAdapter(String fieldName, boolean cached, boolean privileged, Assigner assigner); static InvocationHandlerAdapter of(InvocationHandler invocationHandler); static InvocationHandlerAdapter of(InvocationHandler invocationHandler, String fieldName); static InvocationHandlerAdapter toField(String name); static InvocationHandlerAdapter toField(String name, FieldLocator.Factory fieldLocatorFactory); abstract WithoutPrivilegeConfiguration withoutMethodCache(); abstract Implementation withAssigner(Assigner assigner); abstract AssignerConfigurable withPrivilegedLookup(); }
InvocationHandlerAdapter implements Implementation { public static InvocationHandlerAdapter of(InvocationHandler invocationHandler) { return of(invocationHandler, ForInstance.PREFIX + "$" + RandomString.hashOf(invocationHandler.hashCode())); } protected  InvocationHandlerAdapter(String fieldName, boolean cached, boolean privileged, Assigner assigner); static InvocationHandlerAdapter of(InvocationHandler invocationHandler); static InvocationHandlerAdapter of(InvocationHandler invocationHandler, String fieldName); static InvocationHandlerAdapter toField(String name); static InvocationHandlerAdapter toField(String name, FieldLocator.Factory fieldLocatorFactory); abstract WithoutPrivilegeConfiguration withoutMethodCache(); abstract Implementation withAssigner(Assigner assigner); abstract AssignerConfigurable withPrivilegedLookup();  }