@Override
  public final void dispose() {
    if (unsubscribed.compareAndSet(false, true)) {
      if (AutoDisposeAndroidUtil.isMainThread()) {
        onDispose();
      } else {
        AndroidSchedulers.mainThread().scheduleDirect(this::onDispose);
      }
    }
  }
@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();
  }