org.robolectric.util.Scheduler.areAnyRunnable()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(5.1k)|赞(0)|评价(0)|浏览(108)

本文整理了Java中org.robolectric.util.Scheduler.areAnyRunnable()方法的一些代码示例,展示了Scheduler.areAnyRunnable()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Scheduler.areAnyRunnable()方法的具体详情如下:
包路径:org.robolectric.util.Scheduler
类名称:Scheduler
方法名:areAnyRunnable

Scheduler.areAnyRunnable介绍

[英]Determine if any enqueued runnables are enqueued before the current time.
[中]确定在当前时间之前是否有任何已排队的可运行项已排队。

代码示例

代码示例来源:origin: robolectric/robolectric

@Test
public void shouldResetQueue_whenLooperIsReset() {
 HandlerThread ht = getHandlerThread();
 Looper looper = ht.getLooper();
 Handler h = new Handler(looper);
 ShadowLooper sLooper = shadowOf(looper);
 sLooper.pause();
 h.post(new Runnable() {
  @Override
  public void run() {
  }
 });
 assertThat(shadowOf(looper.getQueue()).getHead()).named("queue").isNotNull();
 sLooper.reset();
 assertThat(sLooper.getScheduler().areAnyRunnable()).named("areAnyRunnable").isFalse();
 assertThat(shadowOf(looper.getQueue()).getHead()).named("queue").isNull();
}

代码示例来源:origin: robolectric/robolectric

@Test
public void shouldNotQueueMessagesIfLooperIsQuit() throws Exception {
 HandlerThread ht = getHandlerThread();
 Looper looper = ht.getLooper();
 looper.quit();
 assertThat(shadowOf(looper).hasQuit()).named("hasQuit").isTrue();
 assertThat(shadowOf(looper).post(new Runnable() {
  @Override
  public void run() {
  }
 }, 0)).named("post").isFalse();
 assertThat(shadowOf(looper).postAtFrontOfQueue(new Runnable() {
  @Override
  public void run() {
  }
 })).named("postAtFrontOfQueue").isFalse();
 assertThat(shadowOf(looper).getScheduler().areAnyRunnable()).named("areAnyRunnable").isFalse();
}

代码示例来源:origin: robolectric/robolectric

@Test
public void shouldThrowawayRunnableQueueIfLooperQuits() throws Exception {
 HandlerThread ht = getHandlerThread();
 Looper looper = ht.getLooper();
 shadowOf(looper).pause();
 shadowOf(looper).post(new Runnable() {
  @Override
  public void run() {
  }
 }, 0);
 looper.quit();
 assertThat(shadowOf(looper).hasQuit()).named("hasQuit").isTrue();
 assertThat(shadowOf(looper).getScheduler().areAnyRunnable()).named("areAnyRunnable").isFalse();
 assertThat(shadowOf(looper.getQueue()).getHead()).named("queue").isNull();
}

代码示例来源:origin: appnexus/mobile-sdk-android

@Override
  public void run() {
    counter[0]--;
    if (uiScheduler.areAnyRunnable() || bgScheduler.areAnyRunnable() || counter[0] == 0) {
      Lock.unpause();
      this.cancel();
    }
  }
}, 0, 100);

代码示例来源:origin: appnexus/mobile-sdk-android

@Override
  public void run() {
    counter[0]--;
    if (uiScheduler.areAnyRunnable() || bgScheduler.areAnyRunnable() || counter[0] == 0) {
      Lock.unpause();
      this.cancel();
    }
  }
}, 0, 100);

代码示例来源:origin: appnexus/mobile-sdk-android

if (Robolectric.getBackgroundThreadScheduler().areAnyRunnable()) {
  Robolectric.flushBackgroundThreadScheduler();
if (Robolectric.getForegroundThreadScheduler().areAnyRunnable()) {
  Robolectric.flushForegroundThreadScheduler();

代码示例来源:origin: appnexus/mobile-sdk-android

@Test
public void test4NoRequestMediationCall() {
  // Create an AdRequest which will request a mediated response
  // that returns an class which does not make an ad request
  // then verify that the correct fail URL request was made
  server.enqueue(new MockResponse().setResponseCode(200).setBody(TestResponsesUT.mediatedNoRequestBanner()));
  server.enqueue(new MockResponse().setResponseCode(200).setBody(TestResponsesUT.blank())); // This is for response URL
  server.enqueue(new MockResponse().setResponseCode(200).setBody(TestResponsesUT.blank())); // This is for no Ad URL
  requestManager.execute();
  Robolectric.flushBackgroundThreadScheduler();
  Robolectric.flushForegroundThreadScheduler();
  try {
    Thread.sleep(20000);
  } catch (InterruptedException e) {
    e.toString();
    //fail(e.toString());
  }
  Robolectric.flushBackgroundThreadScheduler();
  Robolectric.flushForegroundThreadScheduler();
  executeAndAssertResponseURL(2, INTERNAL_ERROR, CHECK_LATENCY_TRUE);
  if (Robolectric.getBackgroundThreadScheduler().areAnyRunnable()) {
    Robolectric.flushBackgroundThreadScheduler();
  }
  if (Robolectric.getForegroundThreadScheduler().areAnyRunnable()) {
    Robolectric.flushForegroundThreadScheduler();
  }
  assertCallbacks(false);
  assertTrue(MediatedBannerNoRequest.didInstantiate);
  assertNoAdURL();
}

代码示例来源:origin: appnexus/mobile-sdk-android

@Test
public void testStop() {
  if (adFetcher != null) {
    // not needed, but in case AdRequest is run
    server.enqueue(new MockResponse().setResponseCode(200).setBody(TestResponsesUT.blank()));
    clearAAIDAsyncTasks();
    // start an AdFetcher normally, until an AdRequest is queued
    adFetcher.start();
    Lock.pause(1000); // added this so jenkins can have enough time to process
    assertExpectedBGTasksAfterOneAdRequest(1);
    assertNotSame(AdFetcher.STATE.STOPPED, adFetcher.getState());
    adFetcher.stop();
    // pause until a scheduler has a task in queue
    waitForTasks();
    // Run the cancel command on AdRequest
    Robolectric.flushForegroundThreadScheduler();
    // Run the pending AdRequest from start() -- should have been canceled
    while (Robolectric.getBackgroundThreadScheduler().areAnyRunnable()) {
      Robolectric.getBackgroundThreadScheduler().runOneTask();
    }
    // A normally executed AdRequest will queue onPostExecute call to the UI thread,
    // but it should be canceled, and queue nothing
    int uiTaskCount = Robolectric.getForegroundThreadScheduler().size();
    assertEquals(0, uiTaskCount);
    assertEquals(AdFetcher.STATE.STOPPED, adFetcher.getState());
  }
}

相关文章