NullObject implements InvocationHandler { @Nullable T get() { return targetRef == null ? null : targetRef.get(); } NullObject(@Nullable T target); @Override Object invoke(Object proxy, Method method, Object[] args);  }
@Test public void shouldHaveWeakTarget() { final NullObject<TestViewCallbacks> nullObject = new NullObject<>(target); target = null; System.gc(); assertThat(nullObject.get()).isNull(); }
@Test public void shouldReturnPassedTarget() { final NullObject<TestViewCallbacks> nullObject1 = new NullObject<>(target); assertThat(nullObject1.get()).isSameAs(target); final NullObject<TestViewCallbacks> nullObject2 = new NullObject<>(null); assertThat(nullObject2.get()).isNull(); }