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

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

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

Scheduler.advanceToNextPostedRunnable介绍

[英]Run the next runnable in the queue.
[中]运行队列中的下一个runnable。

代码示例

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

@Override
 public V get() throws InterruptedException, ExecutionException {
  while (!isDone()) {
   scheduler.advanceToNextPostedRunnable();
  }
  return super.get();
 }
}

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

/**
 * Causes the next {@link Runnable}(s) that have been scheduled to run while advancing the scheduler's clock to its
 * start time. If more than one {@link Runnable} is scheduled to run at this time then they will all be run.
 */
public void runToNextTask() {
 getScheduler().advanceToNextPostedRunnable();
}

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

@Test
public void dispatchedMessage_isMarkedInUse_andRecycled() {
 Handler handler =
   new Handler(looper) {
    @Override
    public void handleMessage(Message msg) {
     boolean inUse = callInstanceMethod(msg, "isInUse");
     assertThat(inUse).named(msg.what + ":inUse").isTrue();
     Message next = reflector(_Message_.class, msg).getNext();
     assertThat(next).named(msg.what + ":next").isNull();
    }
   };
 Message msg = handler.obtainMessage(1);
 enqueueMessage(msg, 200);
 Message msg2 = handler.obtainMessage(2);
 enqueueMessage(msg2, 205);
 scheduler.advanceToNextPostedRunnable();
 
 // Check that it's been properly recycled.
 assertThat(msg.what).named("msg.what").isEqualTo(0);
 
 scheduler.advanceToNextPostedRunnable();
 assertThat(msg2.what).named("msg2.what").isEqualTo(0);
}

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

@Test
public void setAnimation() {
 TestView view = new TestView(buildActivity(Activity.class).create().get());
 AlphaAnimation animation = new AlphaAnimation(0, 1);
 Animation.AnimationListener listener = mock(Animation.AnimationListener.class);
 animation.setAnimationListener(listener);
 animation.setStartTime(1000);
 view.setAnimation(animation);
 verifyZeroInteractions(listener);
 Robolectric.getForegroundThreadScheduler().advanceToNextPostedRunnable();
 verify(listener).onAnimationStart(animation);
 verify(listener).onAnimationEnd(animation);
}

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

@Test
public void vibrateMilliseconds() {
 vibrator.vibrate(5000);
 assertThat(shadowOf(vibrator).isVibrating()).isTrue();
 assertThat(shadowOf(vibrator).getMilliseconds()).isEqualTo(5000L);
 Robolectric.getForegroundThreadScheduler().advanceToNextPostedRunnable();
 assertThat(shadowOf(vibrator).isVibrating()).isFalse();
}

代码示例来源:origin: org.robolectric/framework

/**
 * Causes the next {@link Runnable}(s) that have been scheduled to run while advancing the scheduler's clock to its
 * start time. If more than one {@link Runnable} is scheduled to run at this time then they will all be run.
 */
public void runToNextTask() {
 getScheduler().advanceToNextPostedRunnable();
}

代码示例来源:origin: org.robolectric/shadows-core-v23

/**
 * Causes the next {@link Runnable}(s) that have been scheduled to run while advancing the scheduler's clock to its
 * start time. If more than one {@link Runnable} is scheduled to run at this time then they will all be run.
 */
public void runToNextTask() {
 getScheduler().advanceToNextPostedRunnable();
}

代码示例来源:origin: org.robolectric/shadows-framework

@Override
 public V get() throws InterruptedException, ExecutionException {
  while (!isDone()) {
   scheduler.advanceToNextPostedRunnable();
  }
  return super.get();
 }
}

代码示例来源:origin: org.robolectric/shadows-framework

/**
 * Causes the next {@link Runnable}(s) that have been scheduled to run while advancing the scheduler's clock to its
 * start time. If more than one {@link Runnable} is scheduled to run at this time then they will all be run.
 */
public void runToNextTask() {
 getScheduler().advanceToNextPostedRunnable();
}

代码示例来源:origin: org.robolectric/shadows-core

/**
 * Causes the next {@link Runnable}(s) that have been scheduled to run while advancing the scheduler's clock to its
 * start time. If more than one {@link Runnable} is scheduled to run at this time then they will all be run.
 */
public void runToNextTask() {
 getScheduler().advanceToNextPostedRunnable();
}

代码示例来源:origin: org.robolectric/shadows-core-v23

@Override
 public V get() throws InterruptedException, ExecutionException {
  while (!isDone()) {
   scheduler.advanceToNextPostedRunnable();
  }
  return super.get();
 }
}

代码示例来源:origin: org.robolectric/shadows-core

@Override
 public V get() throws InterruptedException, ExecutionException {
  while (!isDone()) {
   scheduler.advanceToNextPostedRunnable();
  }
  return super.get();
 }
}

代码示例来源:origin: org.robolectric/framework

@Override
 public V get() throws InterruptedException, ExecutionException {
  while (!isDone()) {
   scheduler.advanceToNextPostedRunnable();
  }
  return super.get();
 }
}

代码示例来源:origin: alessandrojp/android-easy-checkout

private void getPurchasesError(PurchaseType type) throws InterruptedException, RemoteException {
    Bundle stubBundle = new Bundle();

    mServiceStub.setServiceForBinding(stubBundle);

    TestSubscriber<Purchases> ts = new TestSubscriber<>();
    mProcessor.getPurchases(type).subscribe(ts);
    shadowOf(mWorkHandler.getLooper()).getScheduler().advanceToNextPostedRunnable();

    assertThat(ts.getOnNextEvents()).isEmpty();

    BillingException e = (BillingException) ts.getOnErrorEvents().get(0);
    assertThat(e.getErrorCode()).isEqualTo(Constants.ERROR_UNEXPECTED_TYPE);
    assertThat(e.getMessage()).isEqualTo(Constants.ERROR_MSG_UNEXPECTED_BUNDLE_RESPONSE_NULL);
  }
}

代码示例来源:origin: alessandrojp/android-easy-checkout

private void getInventoryError(PurchaseType type) throws InterruptedException, RemoteException {
    Bundle stubBundle = new Bundle();

    mServiceStub.setServiceForBinding(stubBundle);

    TestSubscriber<Purchases> ts = new TestSubscriber<>();
    mProcessor.getInventory(type).subscribe(ts);
    shadowOf(mWorkHandler.getLooper()).getScheduler().advanceToNextPostedRunnable();

    assertThat(ts.getOnNextEvents()).isEmpty();

    BillingException e = (BillingException) ts.getOnErrorEvents().get(0);
    assertThat(e.getErrorCode()).isEqualTo(Constants.ERROR_UNEXPECTED_TYPE);
    assertThat(e.getMessage()).isEqualTo(Constants.ERROR_MSG_UNEXPECTED_BUNDLE_RESPONSE_NULL);
  }
}

代码示例来源:origin: alessandrojp/android-easy-checkout

private void getItemDetailsError(PurchaseType type) throws InterruptedException, RemoteException {
    ArrayList<String> itemIds = mDataConverter.convertToSkuItemDetailsJsonArrayList(10);
    Bundle stubBundle = new Bundle();

    mServiceStub.setServiceForBinding(stubBundle);

    TestSubscriber<ItemDetails> ts = new TestSubscriber<>();
    mProcessor.getItemDetails(type, itemIds).subscribe(ts);
    shadowOf(mWorkHandler.getLooper()).getScheduler().advanceToNextPostedRunnable();

    assertThat(ts.getOnNextEvents()).isEmpty();

    BillingException e = (BillingException) ts.getOnErrorEvents().get(0);
    assertThat(e.getErrorCode()).isEqualTo(Constants.ERROR_UNEXPECTED_TYPE);
    assertThat(e.getMessage()).isEqualTo(Constants.ERROR_MSG_UNEXPECTED_BUNDLE_RESPONSE_NULL);
  }
}

代码示例来源:origin: alessandrojp/android-easy-checkout

@Test
public void consumePurchase() throws InterruptedException, RemoteException {
  int responseCode = 0;
  Bundle responseBundle = mDataConverter.convertToPurchaseResponseBundle(0, 0, 10, null);
  Bundle stubBundle = new Bundle();
  stubBundle.putInt(ServiceStub.CONSUME_PURCHASE, responseCode);
  stubBundle.putParcelable(ServiceStub.GET_PURCHASES, responseBundle);
  mServiceStub.setServiceForBinding(stubBundle);
  String itemId = String.format(Locale.US, "%s_%d", DataConverter.TEST_PRODUCT_ID, 0);
  TestSubscriber<Void> ts = new TestSubscriber<>();
  mProcessor.consume(itemId).subscribe(ts);
  shadowOf(mWorkHandler.getLooper()).getScheduler().advanceToNextPostedRunnable();
  assertThat(ts.getOnNextEvents()).isEmpty();
  assertThat(ts.getOnErrorEvents()).isEmpty();
}

代码示例来源:origin: alessandrojp/android-easy-checkout

@Test
  public void consumePurchaseError() {
    Bundle stubBundle = new Bundle();

    mServiceStub.setServiceForBinding(stubBundle);

    TestSubscriber<Void> ts = new TestSubscriber<>();

    mProcessor.consume(DataConverter.TEST_PRODUCT_ID).subscribe(ts);
    shadowOf(mWorkHandler.getLooper()).getScheduler().advanceToNextPostedRunnable();

    assertThat(ts.getOnNextEvents()).isEmpty();

    BillingException e = (BillingException) ts.getOnErrorEvents().get(0);
    assertThat(e.getErrorCode()).isEqualTo(Constants.ERROR_UNEXPECTED_TYPE);
    assertThat(e.getMessage()).isEqualTo(Constants.ERROR_MSG_UNEXPECTED_BUNDLE_RESPONSE_NULL);
  }
}

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

@Test
public void testGetCreativeURL() throws Exception {
  server.enqueue(new MockResponse().setResponseCode(200).setBody(TestUTResponses.video()));
  videoAd.loadAd();
  Lock.pause(1000);
  waitForTasks();
  Robolectric.flushForegroundThreadScheduler();
  Robolectric.flushBackgroundThreadScheduler();
  waitForTasks();
  Robolectric.getBackgroundThreadScheduler().advanceToNextPostedRunnable();
  Robolectric.getForegroundThreadScheduler().advanceToNextPostedRunnable();
  assertAdLoaded(true);
  Clog.w(TestUtil.testLogTag, "VideoAdTest videoAd.getCreativeURL()" +videoAd.getCreativeURL());
  assertTrue(videoAd.getCreativeURL().equalsIgnoreCase("http://vcdn.adnxs.com/p/creative-video/ef/a6/d0/bb/efa6d0bb-8c19-44a8-b140-4b0bc2e02087/efa6d0bb-8c19-44a8-b140-4b0bc2e02087_768_432_500k.mp4"));
}

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

@Test
public void testGetVideoAdDuration() throws Exception {
  server.enqueue(new MockResponse().setResponseCode(200).setBody(TestUTResponses.video()));
  videoAd.loadAd();
  Lock.pause(1000);
  waitForTasks();
  Robolectric.flushForegroundThreadScheduler();
  Robolectric.flushBackgroundThreadScheduler();
  waitForTasks();
  Robolectric.getBackgroundThreadScheduler().advanceToNextPostedRunnable();
  Robolectric.getForegroundThreadScheduler().advanceToNextPostedRunnable();
  assertAdLoaded(true);
  Clog.w(TestUtil.testLogTag, "VideoAdTest videoAd.getCreativeURL()" +videoAd.getCreativeURL());
  assertTrue(videoAd.getVideoAdDuration() == 145000);
}

相关文章