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

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

本文整理了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

  1. @Override
  2. public V get() throws InterruptedException, ExecutionException {
  3. while (!isDone()) {
  4. scheduler.advanceToNextPostedRunnable();
  5. }
  6. return super.get();
  7. }
  8. }

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

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

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

  1. @Test
  2. public void dispatchedMessage_isMarkedInUse_andRecycled() {
  3. Handler handler =
  4. new Handler(looper) {
  5. @Override
  6. public void handleMessage(Message msg) {
  7. boolean inUse = callInstanceMethod(msg, "isInUse");
  8. assertThat(inUse).named(msg.what + ":inUse").isTrue();
  9. Message next = reflector(_Message_.class, msg).getNext();
  10. assertThat(next).named(msg.what + ":next").isNull();
  11. }
  12. };
  13. Message msg = handler.obtainMessage(1);
  14. enqueueMessage(msg, 200);
  15. Message msg2 = handler.obtainMessage(2);
  16. enqueueMessage(msg2, 205);
  17. scheduler.advanceToNextPostedRunnable();
  18. // Check that it's been properly recycled.
  19. assertThat(msg.what).named("msg.what").isEqualTo(0);
  20. scheduler.advanceToNextPostedRunnable();
  21. assertThat(msg2.what).named("msg2.what").isEqualTo(0);
  22. }

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

  1. @Test
  2. public void setAnimation() {
  3. TestView view = new TestView(buildActivity(Activity.class).create().get());
  4. AlphaAnimation animation = new AlphaAnimation(0, 1);
  5. Animation.AnimationListener listener = mock(Animation.AnimationListener.class);
  6. animation.setAnimationListener(listener);
  7. animation.setStartTime(1000);
  8. view.setAnimation(animation);
  9. verifyZeroInteractions(listener);
  10. Robolectric.getForegroundThreadScheduler().advanceToNextPostedRunnable();
  11. verify(listener).onAnimationStart(animation);
  12. verify(listener).onAnimationEnd(animation);
  13. }

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

  1. @Test
  2. public void vibrateMilliseconds() {
  3. vibrator.vibrate(5000);
  4. assertThat(shadowOf(vibrator).isVibrating()).isTrue();
  5. assertThat(shadowOf(vibrator).getMilliseconds()).isEqualTo(5000L);
  6. Robolectric.getForegroundThreadScheduler().advanceToNextPostedRunnable();
  7. assertThat(shadowOf(vibrator).isVibrating()).isFalse();
  8. }

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

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

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

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

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

  1. @Override
  2. public V get() throws InterruptedException, ExecutionException {
  3. while (!isDone()) {
  4. scheduler.advanceToNextPostedRunnable();
  5. }
  6. return super.get();
  7. }
  8. }

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

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

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

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

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

  1. @Override
  2. public V get() throws InterruptedException, ExecutionException {
  3. while (!isDone()) {
  4. scheduler.advanceToNextPostedRunnable();
  5. }
  6. return super.get();
  7. }
  8. }

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

  1. @Override
  2. public V get() throws InterruptedException, ExecutionException {
  3. while (!isDone()) {
  4. scheduler.advanceToNextPostedRunnable();
  5. }
  6. return super.get();
  7. }
  8. }

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

  1. @Override
  2. public V get() throws InterruptedException, ExecutionException {
  3. while (!isDone()) {
  4. scheduler.advanceToNextPostedRunnable();
  5. }
  6. return super.get();
  7. }
  8. }

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

  1. private void getPurchasesError(PurchaseType type) throws InterruptedException, RemoteException {
  2. Bundle stubBundle = new Bundle();
  3. mServiceStub.setServiceForBinding(stubBundle);
  4. TestSubscriber<Purchases> ts = new TestSubscriber<>();
  5. mProcessor.getPurchases(type).subscribe(ts);
  6. shadowOf(mWorkHandler.getLooper()).getScheduler().advanceToNextPostedRunnable();
  7. assertThat(ts.getOnNextEvents()).isEmpty();
  8. BillingException e = (BillingException) ts.getOnErrorEvents().get(0);
  9. assertThat(e.getErrorCode()).isEqualTo(Constants.ERROR_UNEXPECTED_TYPE);
  10. assertThat(e.getMessage()).isEqualTo(Constants.ERROR_MSG_UNEXPECTED_BUNDLE_RESPONSE_NULL);
  11. }
  12. }

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

  1. private void getInventoryError(PurchaseType type) throws InterruptedException, RemoteException {
  2. Bundle stubBundle = new Bundle();
  3. mServiceStub.setServiceForBinding(stubBundle);
  4. TestSubscriber<Purchases> ts = new TestSubscriber<>();
  5. mProcessor.getInventory(type).subscribe(ts);
  6. shadowOf(mWorkHandler.getLooper()).getScheduler().advanceToNextPostedRunnable();
  7. assertThat(ts.getOnNextEvents()).isEmpty();
  8. BillingException e = (BillingException) ts.getOnErrorEvents().get(0);
  9. assertThat(e.getErrorCode()).isEqualTo(Constants.ERROR_UNEXPECTED_TYPE);
  10. assertThat(e.getMessage()).isEqualTo(Constants.ERROR_MSG_UNEXPECTED_BUNDLE_RESPONSE_NULL);
  11. }
  12. }

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

  1. private void getItemDetailsError(PurchaseType type) throws InterruptedException, RemoteException {
  2. ArrayList<String> itemIds = mDataConverter.convertToSkuItemDetailsJsonArrayList(10);
  3. Bundle stubBundle = new Bundle();
  4. mServiceStub.setServiceForBinding(stubBundle);
  5. TestSubscriber<ItemDetails> ts = new TestSubscriber<>();
  6. mProcessor.getItemDetails(type, itemIds).subscribe(ts);
  7. shadowOf(mWorkHandler.getLooper()).getScheduler().advanceToNextPostedRunnable();
  8. assertThat(ts.getOnNextEvents()).isEmpty();
  9. BillingException e = (BillingException) ts.getOnErrorEvents().get(0);
  10. assertThat(e.getErrorCode()).isEqualTo(Constants.ERROR_UNEXPECTED_TYPE);
  11. assertThat(e.getMessage()).isEqualTo(Constants.ERROR_MSG_UNEXPECTED_BUNDLE_RESPONSE_NULL);
  12. }
  13. }

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

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

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

  1. @Test
  2. public void consumePurchaseError() {
  3. Bundle stubBundle = new Bundle();
  4. mServiceStub.setServiceForBinding(stubBundle);
  5. TestSubscriber<Void> ts = new TestSubscriber<>();
  6. mProcessor.consume(DataConverter.TEST_PRODUCT_ID).subscribe(ts);
  7. shadowOf(mWorkHandler.getLooper()).getScheduler().advanceToNextPostedRunnable();
  8. assertThat(ts.getOnNextEvents()).isEmpty();
  9. BillingException e = (BillingException) ts.getOnErrorEvents().get(0);
  10. assertThat(e.getErrorCode()).isEqualTo(Constants.ERROR_UNEXPECTED_TYPE);
  11. assertThat(e.getMessage()).isEqualTo(Constants.ERROR_MSG_UNEXPECTED_BUNDLE_RESPONSE_NULL);
  12. }
  13. }

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

  1. @Test
  2. public void testGetCreativeURL() throws Exception {
  3. server.enqueue(new MockResponse().setResponseCode(200).setBody(TestUTResponses.video()));
  4. videoAd.loadAd();
  5. Lock.pause(1000);
  6. waitForTasks();
  7. Robolectric.flushForegroundThreadScheduler();
  8. Robolectric.flushBackgroundThreadScheduler();
  9. waitForTasks();
  10. Robolectric.getBackgroundThreadScheduler().advanceToNextPostedRunnable();
  11. Robolectric.getForegroundThreadScheduler().advanceToNextPostedRunnable();
  12. assertAdLoaded(true);
  13. Clog.w(TestUtil.testLogTag, "VideoAdTest videoAd.getCreativeURL()" +videoAd.getCreativeURL());
  14. 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"));
  15. }

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

  1. @Test
  2. public void testGetVideoAdDuration() throws Exception {
  3. server.enqueue(new MockResponse().setResponseCode(200).setBody(TestUTResponses.video()));
  4. videoAd.loadAd();
  5. Lock.pause(1000);
  6. waitForTasks();
  7. Robolectric.flushForegroundThreadScheduler();
  8. Robolectric.flushBackgroundThreadScheduler();
  9. waitForTasks();
  10. Robolectric.getBackgroundThreadScheduler().advanceToNextPostedRunnable();
  11. Robolectric.getForegroundThreadScheduler().advanceToNextPostedRunnable();
  12. assertAdLoaded(true);
  13. Clog.w(TestUtil.testLogTag, "VideoAdTest videoAd.getCreativeURL()" +videoAd.getCreativeURL());
  14. assertTrue(videoAd.getVideoAdDuration() == 145000);
  15. }

相关文章