void () { List<Disposable> run = new ArrayList<>(); //noinspection EqualsWhichDoesntCheckParameterClass Disposable disposable0 = new Disposable() { @Override public void dispose() { } @Override public int hashCode() { return 0; } @Override public boolean equals(Object obj) { return true; } }; //noinspection EqualsWhichDoesntCheckParameterClass Disposable disposable1 = new Disposable() { @Override public void dispose() { } @Override public int hashCode() { return 0; } @Override public boolean equals(Object obj) { return true; } }; assertEquals(disposable0, disposable1); Disposable child0 = new Disposable() { @Override public void dispose() { run.add(this); } }; Disposable child1 = new Disposable() { @Override public void dispose() { run.add(this); } }; Disposer.register(disposable0, child0); Disposer.register(disposable1, child1); Disposer.dispose(disposable0); assertSame(child0, UsefulTestCase.assertOneElement(run)); run.clear(); Disposer.dispose(disposable1); assertSame(child1, UsefulTestCase.assertOneElement(run)); }