RefCountSubscription implements Subscription { @Override public void unsubscribe() { State oldState; State newState; do { oldState = state; if (oldState.isUnsubscribed) { return; } newState = oldState.unsubscribe(); } while (!STATE_UPDATER.compareAndSet(this, oldState, newState)); unsubscribeActualIfApplicable(newState); } RefCountSubscription(Subscription s); Subscription get(); @Override boolean isUnsubscribed(); @Override void unsubscribe();  }
@Test public void testImmediateUnsubscribe() { InOrder inOrder = inOrder(main); rcs.unsubscribe(); inOrder.verify(main, times(1)).call(); rcs.unsubscribe(); inOrder.verifyNoMoreInteractions(); }