@Test public void testSingleSet() { AsyncSubscription as = new AsyncSubscription(); Subscription s = mock(Subscription.class); assertTrue(as.setSubscription(s)); Subscription s1 = mock(Subscription.class); assertTrue(as.setSubscription(s1)); assertSame(as.actual, s); verify(s1).cancel(); }
@Test public void testCancelBeforeSet() { AsyncSubscription as = new AsyncSubscription(); Subscription s = mock(Subscription.class); as.request(1); as.cancel(); assertFalse(as.setSubscription(s)); verify(s, never()).request(1); verify(s).cancel(); }
@Test public void testNoResource() { AsyncSubscription as = new AsyncSubscription(); Subscription s = mock(Subscription.class); assertTrue(as.setSubscription(s)); as.request(1); as.cancel(); verify(s).request(1); verify(s).cancel(); }
@Test public void testCancelOnce() { Disposable r = mock(Disposable.class); AsyncSubscription as = new AsyncSubscription(r); Subscription s = mock(Subscription.class); assertTrue(as.setSubscription(s)); as.cancel(); as.cancel(); as.cancel(); verify(s, never()).request(anyLong()); verify(s).cancel(); verify(r).dispose(); }