Disposables { @NonNull public static Disposable fromAction(@NonNull Action run) { ObjectHelper.requireNonNull(run, "run is null"); return new ActionDisposable(run); } private  Disposables(); @NonNull static Disposable fromRunnable(@NonNull Runnable run); @NonNull static Disposable fromAction(@NonNull Action run); @NonNull static Disposable fromFuture(@NonNull Future<?> future); @NonNull static Disposable fromFuture(@NonNull Future<?> future, boolean allowInterrupt); @NonNull static Disposable fromSubscription(@NonNull Subscription subscription); @NonNull static Disposable empty(); @NonNull static Disposable disposed();  }
@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 fromActionThrows() { try { Disposables.fromAction(new Action() { @Override public void run() throws Exception { throw new IllegalArgumentException(); } }).dispose(); fail("Should have thrown!"); } catch (IllegalArgumentException ex) { } try { Disposables.fromAction(new Action() { @Override public void run() throws Exception { throw new InternalError(); } }).dispose(); fail("Should have thrown!"); } catch (InternalError ex) { } try { Disposables.fromAction(new Action() { @Override public void run() throws Exception { throw new IOException(); } }).dispose(); fail("Should have thrown!"); } catch (RuntimeException ex) { if (!(ex.getCause() instanceof IOException)) { fail(ex.toString() + ": Should have cause of IOException"); } } }