ListCompositeDisposable implements Disposable, DisposableContainer { @Override public void dispose() { if (disposed) { return; } List<Disposable> set; synchronized (this) { if (disposed) { return; } disposed = true; set = resources; resources = null; } dispose(set); } ListCompositeDisposable();  ListCompositeDisposable(Disposable... resources);  ListCompositeDisposable(Iterable<? extends Disposable> resources); @Override void dispose(); @Override boolean isDisposed(); @Override boolean add(Disposable d); boolean addAll(Disposable... ds); @Override boolean remove(Disposable d); @Override boolean delete(Disposable d); void clear();  }
@Test public void disposeThrows() { Disposable d = new Disposable() { @Override public void dispose() { throw new TestException(); } @Override public boolean isDisposed() { return false; } }; ListCompositeDisposable lcd = new ListCompositeDisposable(d, d); try { lcd.dispose(); fail("Should have thrown!"); } catch (CompositeException ex) { List<Throwable> list = ex.getExceptions(); TestHelper.assertError(list, 0, TestException.class); TestHelper.assertError(list, 1, TestException.class); } lcd = new ListCompositeDisposable(d); try { lcd.dispose(); fail("Should have thrown!"); } catch (TestException ex) { } }
@Test public void disposeRace() { for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { final ListCompositeDisposable cd = new ListCompositeDisposable(); Runnable run = new Runnable() { @Override public void run() { cd.dispose(); } }; TestHelper.race(run, run); } }