本文整理了Java中org.robolectric.util.Scheduler.advanceToLastPostedRunnable()
方法的一些代码示例,展示了Scheduler.advanceToLastPostedRunnable()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Scheduler.advanceToLastPostedRunnable()
方法的具体详情如下:
包路径:org.robolectric.util.Scheduler
类名称:Scheduler
方法名:advanceToLastPostedRunnable
[英]Run all runnables in the queue, and any additional runnables they schedule that are scheduled before the latest scheduled runnable currently in the queue.
[中]运行队列中的所有可运行项,以及在队列中当前最新的可运行项之前计划的任何其他可运行项。
代码示例来源:origin: robolectric/robolectric
/**
* Execute all runnables that have been enqueued on the foreground scheduler.
*/
public static void flushForegroundThreadScheduler() {
getForegroundThreadScheduler().advanceToLastPostedRunnable();
}
代码示例来源:origin: robolectric/robolectric
/**
* Execute all runnables that have been enqueued on the background scheduler.
*/
public static void flushBackgroundThreadScheduler() {
getBackgroundThreadScheduler().advanceToLastPostedRunnable();
}
}
代码示例来源:origin: robolectric/robolectric
/**
* Causes all of the {@link Runnable}s that have been scheduled to run while advancing the scheduler's clock to the
* start time of the last scheduled {@link Runnable}.
*/
public void runToEndOfTasks() {
getScheduler().advanceToLastPostedRunnable();
}
代码示例来源:origin: robolectric/robolectric
@Test
@Config(minSdk = N, maxSdk = N_MR1) // Functionality removed in O
public void whenPackageNotPresentAndPaused_getPackageSizeInfo_callsBackWithFailure()
throws Exception {
Robolectric.getForegroundThreadScheduler().pause();
IPackageStatsObserver packageStatsObserver = mock(IPackageStatsObserver.class);
packageManager.getPackageSizeInfo("nonexistant.package", packageStatsObserver);
verifyZeroInteractions(packageStatsObserver);
Robolectric.getForegroundThreadScheduler().advanceToLastPostedRunnable();
verify(packageStatsObserver).onGetStatsCompleted(packageStatsCaptor.capture(), eq(false));
assertThat(packageStatsCaptor.getValue()).isNull();
}
代码示例来源:origin: robolectric/robolectric
@Test
@Config(minSdk = N, maxSdk = N_MR1) // Functionality removed in O
public void whenPaused_getPackageSizeInfo_callsBackWithConfiguredValuesAfterIdle()
throws Exception {
Robolectric.getForegroundThreadScheduler().pause();
IPackageStatsObserver packageStatsObserver = mock(IPackageStatsObserver.class);
packageManager.getPackageSizeInfo("org.robolectric", packageStatsObserver);
verifyZeroInteractions(packageStatsObserver);
Robolectric.getForegroundThreadScheduler().advanceToLastPostedRunnable();
verify(packageStatsObserver).onGetStatsCompleted(packageStatsCaptor.capture(), eq(true));
assertThat(packageStatsCaptor.getValue().packageName).isEqualTo("org.robolectric");
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testPendingEventsRemovedOnError() {
Mockito.when(errorListener.onError(mediaPlayer, 2, 3)).thenReturn(true);
shadowMediaPlayer.setState(PREPARED);
mediaPlayer.start();
scheduler.advanceBy(200);
// We should have a pending completion callback.
assertThat(scheduler.size()).isEqualTo(1);
shadowMediaPlayer.invokeErrorListener(2, 3);
assertThat(scheduler.advanceToLastPostedRunnable()).isFalse();
Mockito.verifyZeroInteractions(completionListener);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testSeekDuringPlaybackReschedulesCompletionCallback() {
shadowMediaPlayer.setState(PREPARED);
mediaPlayer.start();
scheduler.advanceBy(300);
mediaPlayer.seekTo(400);
scheduler.advanceBy(599);
Mockito.verifyZeroInteractions(completionListener);
scheduler.advanceBy(1);
Mockito.verify(completionListener).onCompletion(mediaPlayer);
Mockito.verifyNoMoreInteractions(completionListener);
assertThat(shadowMediaPlayer.getState()).isEqualTo(PLAYBACK_COMPLETED);
assertThat(scheduler.advanceToLastPostedRunnable()).isFalse();
Mockito.verifyZeroInteractions(completionListener);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testRemoveEventAtOffset() {
shadowMediaPlayer.setState(PREPARED);
mediaPlayer.start();
scheduler.advanceBy(200);
MediaEvent e = info.scheduleInfoAtOffset(
500, 1, 3);
scheduler.advanceBy(299);
info.removeEventAtOffset(500, e);
scheduler.advanceToLastPostedRunnable();
Mockito.verifyZeroInteractions(infoListener);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void postAndRemoveSyncBarrierToken_syncBefore() {
int token = postSyncBarrier(queue);
enqueueMessage(testMessage, SystemClock.uptimeMillis());
scheduler.advanceToLastPostedRunnable();
removeSyncBarrier(queue, token);
assertThat(shadowQueue.getHead()).isNull();
assertThat(handler.handled).named("handled:after").containsExactly(testMessage);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void postAndRemoveSyncBarrierToken_messageBeforeConsumed() {
enqueueMessage(testMessage, SystemClock.uptimeMillis());
int token = postSyncBarrier(queue);
scheduler.advanceToLastPostedRunnable();
removeSyncBarrier(queue, token);
assertThat(shadowQueue.getHead()).isNull();
assertThat(handler.handled).named("handled:after").containsExactly(testMessage);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void removeFrameCallback_shouldRemoveCallback() {
Choreographer instance = ShadowChoreographer.getInstance();
Choreographer.FrameCallback callback = mock(Choreographer.FrameCallback.class);
instance.postFrameCallbackDelayed(callback, 1000);
instance.removeFrameCallback(callback);
ShadowApplication.getInstance().getForegroundThreadScheduler().advanceToLastPostedRunnable();
verify(callback, never()).doFrame(anyLong());
}
代码示例来源:origin: robolectric/robolectric
@Test
public void postAndRemoveSyncBarrierToken_messageAfter() {
enqueueMessage(testMessage, SystemClock.uptimeMillis() + 100);
int token = postSyncBarrier(queue);
removeSyncBarrier(queue, token);
assertThat(shadowQueue.getHead()).isEqualTo(testMessage);
scheduler.advanceToLastPostedRunnable();
assertThat(shadowQueue.getHead()).isNull();
assertThat(handler.handled).named("handled:after").containsExactly(testMessage);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testScheduleErrorAtOffsetWhileNotPlaying() {
info.scheduleErrorAtOffset(500, 1, 3);
shadowMediaPlayer.setState(INITIALIZED);
shadowMediaPlayer.setState(PREPARED);
mediaPlayer.start();
scheduler.advanceBy(499);
Mockito.verifyZeroInteractions(errorListener);
scheduler.advanceBy(1);
Mockito.verify(errorListener).onError(mediaPlayer, 1, 3);
assertThat(shadowMediaPlayer.getState()).isSameAs(ERROR);
assertThat(scheduler.advanceToLastPostedRunnable()).isFalse();
assertThat(shadowMediaPlayer.getCurrentPositionRaw()).isEqualTo(500);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void enqueueMessage_withZeroWhen_postsAtFront() {
enqueueMessage(testMessage, 0);
Message m2 = handler.obtainMessage(2);
enqueueMessage(m2, 0);
scheduler.advanceToLastPostedRunnable();
assertThat(handler.handled).named("handled").containsExactly(m2, testMessage);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testTimeNotChangedByNegativeDelay() throws Exception {
long currentTime = scheduler.getCurrentTime();
long[] observedTime = new long[1];
scheduler.postDelayed(
new Runnable() {
@Override
public void run() {
observedTime[0] = scheduler.getCurrentTime();
}
},
-1000);
scheduler.advanceToLastPostedRunnable();
assertThat(observedTime[0]).isEqualTo(currentTime);
assertThat(scheduler.getCurrentTime()).isEqualTo(currentTime);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testRemoveEvent() {
shadowMediaPlayer.setState(PREPARED);
mediaPlayer.start();
scheduler.advanceBy(200);
MediaEvent e = info.scheduleInfoAtOffset(500, 1, 3);
scheduler.advanceBy(299);
shadowMediaPlayer.doStop();
info.removeEvent(e);
shadowMediaPlayer.doStart();
scheduler.advanceToLastPostedRunnable();
Mockito.verifyZeroInteractions(infoListener);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void removedMessage_isNotSentToHandler() {
enqueueMessage(testMessage, 200);
assertThat(scheduler.size()).named("scheduler size:before").isEqualTo(1);
removeMessages(handler, testMessage.what, null);
scheduler.advanceToLastPostedRunnable();
assertThat(scheduler.size()).named("scheduler size:after").isEqualTo(0);
assertThat(handler.handled).named("handled").isEmpty();
}
代码示例来源:origin: robolectric/robolectric
@Test
public void remove_ShouldRemoveAllInstancesOfRunnableFromQueue() throws Exception {
scheduler.post(new TestRunnable());
TestRunnable runnable = new TestRunnable();
scheduler.post(runnable);
scheduler.post(runnable);
assertThat(scheduler.size()).isEqualTo(3);
scheduler.remove(runnable);
assertThat(scheduler.size()).isEqualTo(1);
scheduler.advanceToLastPostedRunnable();
assertThat(runnable.wasRun).isFalse();
}
代码示例来源:origin: robolectric/robolectric
@Test
public void delayedTasks_areNotRunEagerly_whenActivityIsStarted_andSchedulerUnPaused() {
// Regression test for issue #1509
final Scheduler s = Robolectric.getForegroundThreadScheduler();
final long startTime = s.getCurrentTime();
TestDelayedPostActivity activity = Robolectric.setupActivity(TestDelayedPostActivity.class);
assertThat(activity.r2.wasRun).named("before flush").isFalse();
assertThat(s.getCurrentTime()).named("currentTime before flush").isEqualTo(startTime);
s.advanceToLastPostedRunnable();
assertThat(activity.r2.wasRun).named("after flush").isTrue();
assertThat(s.getCurrentTime()).named("currentTime after flush").isEqualTo(startTime + 60000);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testSeekWhilePausedDelayedCallback() {
shadowMediaPlayer.setState(PAUSED);
shadowMediaPlayer.setSeekDelay(100);
scheduler.advanceBy(200);
mediaPlayer.seekTo(450);
scheduler.advanceBy(99);
assertThat(mediaPlayer.getCurrentPosition()).isEqualTo(0);
Mockito.verifyZeroInteractions(seekListener);
scheduler.advanceBy(1);
assertThat(mediaPlayer.getCurrentPosition()).isEqualTo(450);
Mockito.verify(seekListener).onSeekComplete(mediaPlayer);
// Check that no completion callback or alternative
// seek callbacks have been scheduled.
assertThat(scheduler.advanceToLastPostedRunnable()).isFalse();
}
内容来源于网络,如有侵权,请联系作者删除!