@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 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);
  }
Exemplo n.º 3
0
 @Implementation
 public void postInvalidateDelayed(long delayMilliseconds) {
   Robolectric.getUiThreadScheduler()
       .postDelayed(
           new Runnable() {
             @Override
             public void run() {
               realView.invalidate();
             }
           },
           delayMilliseconds);
 }
  @Before
  public void setUp() throws Exception {

    ShadowLog.stream = System.out;
    transcript = new Transcript();

    context = new Activity();

    ObsDetails obsDetails = ObsDetails.getInstance();
    obsDetails.setCompanyCode("coco");
    obsDetails.setUsername("david");

    final String[] fList = context.fileList();
    boolean configExists = false;
    f =
        new File(
            HttpMessageConverterTest.class.getClassLoader().getResource(TOKEN_FILE_NAME).toURI());
    Assert.assertTrue(f.exists());

    for (String fname : fList) {
      configExists = configExists || TOKEN_FILE_NAME.equals(fname);
    }
    try {

      f =
          new File(
              HttpMessageConverterTest.class.getClassLoader().getResource(TOKEN_FILE_NAME).toURI());
      Assert.assertTrue(f.exists());

      tokenConfiguration = (new TokenConfiguration()).load(f, "lucky13".toCharArray());
      if (tokenConfiguration.getDomains().size() == 0) {
        TokenConfiguration.save(tokenConfiguration, f, "lucky13".toCharArray());
        setupFacade.init();

      } else {
        Logger.debug("Unable to create token Configuration");
      }
    } catch (Exception e) {
      Logger.debug("HomeMenu" + "Exception thrown: " + e.getMessage());
    }

    Robolectric.getBackgroundScheduler().pause();
    Robolectric.getUiThreadScheduler().pause();
  }
 @Implementation
 public void runOnUiThread(Runnable action) {
   Robolectric.getUiThreadScheduler().post(action);
 }
Exemplo n.º 6
0
 @Implementation
 public void postDelayed(Runnable action, long delayMills) {
   Robolectric.getUiThreadScheduler().postDelayed(action, delayMills);
 }