CompositeSubscription implements Subscription { public void clear() { if (!unsubscribed) { Collection<Subscription> unsubscribe = null; synchronized (this) { if (unsubscribed || subscriptions == null) { return; } else { unsubscribe = subscriptions; subscriptions = null; } } unsubscribeFromAll(unsubscribe); } } CompositeSubscription();  CompositeSubscription(final Subscription... subscriptions); @Override boolean isUnsubscribed(); void add(final Subscription s); void remove(final Subscription s); void clear(); @Override void unsubscribe(); boolean hasSubscriptions();  }
@Test public void testClear() { BooleanSubscription s1 = new BooleanSubscription(); BooleanSubscription s2 = new BooleanSubscription(); CompositeSubscription s = new CompositeSubscription(); s.add(s1); s.add(s2); assertFalse(s1.isUnsubscribed()); assertFalse(s2.isUnsubscribed()); s.clear(); assertTrue(s1.isUnsubscribed()); assertTrue(s2.isUnsubscribed()); assertFalse(s.isUnsubscribed()); BooleanSubscription s3 = new BooleanSubscription(); s.add(s3); s.unsubscribe(); assertTrue(s3.isUnsubscribed()); assertTrue(s.isUnsubscribed()); }