@Test
  public void loadAd_whenCallingOnBannerFailed_shouldCancelExistingTimeoutRunnable()
      throws Exception {
    Robolectric.pauseMainLooper();

    Answer justCallOnBannerFailed =
        new Answer() {
          @Override
          public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
            assertThat(Robolectric.getUiThreadScheduler().enqueuedTaskCount()).isEqualTo(1);
            subject.onBannerFailed(null);
            assertThat(Robolectric.getUiThreadScheduler().enqueuedTaskCount()).isEqualTo(0);
            return null;
          }
        };

    doAnswer(justCallOnBannerFailed)
        .when(banner)
        .loadBanner(
            any(Context.class),
            any(CustomEventBanner.CustomEventBannerListener.class),
            any(Map.class),
            any(Map.class));

    assertThat(Robolectric.getUiThreadScheduler().enqueuedTaskCount()).isEqualTo(0);
    subject.loadAd();
    assertThat(Robolectric.getUiThreadScheduler().enqueuedTaskCount()).isEqualTo(0);
  }
  @Test
  public void shouldQueueUiTasksWhenUiThreadIsPaused() throws Exception {
    Robolectric.pauseMainLooper();

    activity = create(DialogLifeCycleActivity.class);
    TestRunnable runnable = new TestRunnable();
    activity.runOnUiThread(runnable);
    assertFalse(runnable.wasRun);

    Robolectric.unPauseMainLooper();
    assertTrue(runnable.wasRun);
  }
  @Test
  public void loadAd_shouldScheduleTimeout_bannerLoadedAndFailed_shouldCancelTimeout()
      throws Exception {
    Robolectric.pauseMainLooper();

    assertThat(Robolectric.getUiThreadScheduler().enqueuedTaskCount()).isEqualTo(0);

    subject.loadAd();
    assertThat(Robolectric.getUiThreadScheduler().enqueuedTaskCount()).isEqualTo(1);

    subject.onBannerLoaded(null);
    assertThat(Robolectric.getUiThreadScheduler().enqueuedTaskCount()).isEqualTo(0);

    subject.loadAd();
    assertThat(Robolectric.getUiThreadScheduler().enqueuedTaskCount()).isEqualTo(1);

    subject.onBannerFailed(null);
    assertThat(Robolectric.getUiThreadScheduler().enqueuedTaskCount()).isEqualTo(0);
  }