@Test public void onDispose_defersToMainThreadHook() { AutoDisposeAndroidPlugins.setOnCheckMainThread(() -> true); final AtomicBoolean called = new AtomicBoolean(); new MainThreadDisposable() { @Override protected void onDispose() { called.set(true); } }.dispose(); assertThat(called.get()).isTrue(); }
@Override public final void dispose() { if (unsubscribed.compareAndSet(false, true)) { if (AutoDisposeAndroidUtil.isMainThread()) { onDispose(); } else { AndroidSchedulers.mainThread().scheduleDirect(this::onDispose); } } }
MainThreadDisposable implements Disposable { @Override public final void dispose() { if (unsubscribed.compareAndSet(false, true)) { if (AutoDisposeAndroidUtil.isMainThread()) { onDispose(); } else { AndroidSchedulers.mainThread().scheduleDirect(this::onDispose); } } } }
MainThreadDisposable implements Disposable { @Override public final void dispose() { if (unsubscribed.compareAndSet(false, true)) { if (AutoDisposeAndroidUtil.isMainThread()) { onDispose(); } else { AndroidSchedulers.mainThread().scheduleDirect(this::onDispose); } } }  }
MainThreadDisposable implements Disposable { @Override public final void dispose() { if (unsubscribed.compareAndSet(false, true)) { if (AutoDisposeAndroidUtil.isMainThread()) { onDispose(); } else { AndroidSchedulers.mainThread().scheduleDirect(this::onDispose); } } }  @Override final boolean isDisposed(); @Override final void dispose(); }
MainThreadDisposable implements Disposable { @Override public final void dispose() { if (unsubscribed.compareAndSet(false, true)) { if (AutoDisposeAndroidUtil.isMainThread()) { onDispose(); } else { AndroidSchedulers.mainThread().scheduleDirect(this::onDispose); } } }  @Override final boolean isDisposed(); @Override final void dispose();  }