Disposables { @NonNull public static Disposable empty() { return fromRunnable(Functions.EMPTY_RUNNABLE); } 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 testEmpty() { Disposable empty = Disposables.empty(); assertFalse(empty.isDisposed()); empty.dispose(); assertTrue(empty.isDisposed()); }
@Test public void disposeRace() { for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { final Disposable d = Disposables.empty(); Runnable r = new Runnable() { @Override public void run() { d.dispose(); } }; TestHelper.race(r, r); } }
@Test public void setOnceTwice() { List<Throwable> errors = TestHelper.trackPluginErrors(); try { AtomicReference<Disposable> target = new AtomicReference<Disposable>(); Disposable d = Disposables.empty(); DisposableHelper.setOnce(target, d); Disposable d1 = Disposables.empty(); DisposableHelper.setOnce(target, d1); assertTrue(d1.isDisposed()); TestHelper.assertError(errors, 0, IllegalStateException.class, "Disposable already set!"); } finally { RxJavaPlugins.reset(); } }