@Test public void fromActionThrows() { try { Disposables.fromAction(new Action() { @Override public void run() throws Exception { Disposables.fromAction(new Action() { @Override public void run() throws Exception { Disposables.fromAction(new Action() { @Override public void run() throws Exception {
@Test public void fromAction() { class AtomicAction extends AtomicBoolean implements Action { private static final long serialVersionUID = -1517510584253657229L; @Override public void run() throws Exception { set(true); } } AtomicAction aa = new AtomicAction(); Disposables.fromAction(aa).dispose(); assertTrue(aa.get()); }
@Test public void disposeThrowsCheckedException() { CompositeDisposable cd = new CompositeDisposable(); cd.add(Disposables.fromAction(new Action() { @Override public void run() throws Exception { throw new IOException(); } })); Disposable d1 = Disposables.empty(); cd.add(d1); try { cd.dispose(); fail("Failed to throw"); } catch (RuntimeException ex) { // expected if (!(ex.getCause() instanceof IOException)) { fail(ex.toString() + " should have thrown RuntimeException(IOException)"); } } assertTrue(d1.isDisposed()); }
@Test public void disposeThrowsError() { CompositeDisposable cd = new CompositeDisposable(); cd.add(Disposables.fromAction(new Action() { @Override public void run() throws Exception { throw new AssertionError(); } })); Disposable d1 = Disposables.empty(); cd.add(d1); try { cd.dispose(); fail("Failed to throw"); } catch (AssertionError ex) { // expected } assertTrue(d1.isDisposed()); }
@Test public void disposeThrowsIAE() { CompositeDisposable cd = new CompositeDisposable(); cd.add(Disposables.fromAction(new Action() { @Override public void run() throws Exception { throw new IllegalArgumentException(); } })); Disposable d1 = Disposables.empty(); cd.add(d1); try { cd.dispose(); fail("Failed to throw"); } catch (IllegalArgumentException ex) { // expected } assertTrue(d1.isDisposed()); }