CompositeSubscription implements Subscription { public void add(final Subscription s) { if (s.isUnsubscribed()) { return; } if (!unsubscribed) { synchronized (this) { if (!unsubscribed) { if (subscriptions == null) { subscriptions = new HashSet<Subscription>(4); } subscriptions.add(s); return; } } } s.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(expected = NullPointerException.class) public void testAddingNullSubscriptionIllegal() { CompositeSubscription csub = new CompositeSubscription(); csub.add(null); }