AsyncContext { @SuppressWarnings("unchecked") protected void releaseData(final D data) { if (async instanceof Releaser) { ((Releaser<D>) async).release(data); } } AsyncContext(final Context context, final Async<D> async);   }
@Test public void releaseShouldDelegateReleaser() { class TestAsync implements Async<String>, Releaser<String> { @Override public void subscribe(AsyncObserver<String> observer) { } @Override public void cancel() { } @Override public Async<String> replicate() { return this; } @Override public void release(String data) { } } TestAsync mock = mock(TestAsync.class); AsyncContext<String> context = new AsyncContext<>(mock(Context.class), mock); context.releaseData("test"); verify(mock).release("test"); }