@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();
  }
  @Test
  public void testInitialResource() {
    Disposable r = mock(Disposable.class);
    AsyncSubscription as = new AsyncSubscription(r);

    as.cancel();

    verify(r).dispose();
  }
  @Test
  public void testReplaceResourceAfterCancel() {
    AsyncSubscription as = new AsyncSubscription();
    as.cancel();

    Disposable r = mock(Disposable.class);

    assertFalse(as.replaceResource(r));

    verify(r).dispose();
  }
  @Test
  public void testSetResource() {
    AsyncSubscription as = new AsyncSubscription();

    Disposable r = mock(Disposable.class);

    assertTrue(as.setResource(r));

    as.cancel();

    verify(r).dispose();
  }
  @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 testReplaceResource2() {
    AsyncSubscription as = new AsyncSubscription();

    Disposable r = mock(Disposable.class);

    assertTrue(as.replaceResource(r));

    Disposable r2 = mock(Disposable.class);

    assertTrue(as.replaceResource(r2));

    as.cancel();

    verify(r, never()).dispose();
    verify(r2).dispose();
  }