本文整理了Java中org.robolectric.util.Scheduler.advanceBy()
方法的一些代码示例,展示了Scheduler.advanceBy()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Scheduler.advanceBy()
方法的具体详情如下:
包路径:org.robolectric.util.Scheduler
类名称:Scheduler
方法名:advanceBy
[英]Run all runnables that are scheduled to run in the next time interval.
[中]运行计划在下一个时间间隔内运行的所有可运行程序。
代码示例来源:origin: robolectric/robolectric
/**
* Run all runnables that are scheduled to run in the next time interval.
*
* @param interval Time interval (in millis).
* @return True if a runnable was executed.
* @deprecated Use {@link #advanceBy(long, TimeUnit)}.
*/
@Deprecated
public synchronized boolean advanceBy(long interval) {
return advanceBy(interval, TimeUnit.MILLISECONDS);
}
代码示例来源:origin: robolectric/robolectric
/**
* Causes {@link Runnable}s that have been scheduled to run within the next specified amount of time to run while
* advancing the scheduler's clock.
*/
public void idle(long amount, TimeUnit unit) {
getScheduler().advanceBy(amount, unit);
}
代码示例来源:origin: robolectric/robolectric
/**
* Runs any background tasks previously queued by {@link android.os.AsyncTask#execute(Object[])}.
*
* Note: calling this method does not pause or un-pause the scheduler.
*/
public static void runBackgroundTasks() {
getInstance().getBackgroundThreadScheduler().advanceBy(0);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testPauseReschedulesCompletionCallback() {
shadowMediaPlayer.setState(PREPARED);
mediaPlayer.start();
scheduler.advanceBy(200);
mediaPlayer.pause();
scheduler.advanceBy(800);
Mockito.verifyZeroInteractions(completionListener);
mediaPlayer.start();
scheduler.advanceBy(799);
Mockito.verifyZeroInteractions(completionListener);
scheduler.advanceBy(1);
Mockito.verify(completionListener).onCompletion(mediaPlayer);
Mockito.verifyNoMoreInteractions(completionListener);
assertThat(scheduler.advanceToLastPostedRunnable()).isFalse();
Mockito.verifyZeroInteractions(completionListener);
}
代码示例来源:origin: robolectric/robolectric
@Implementation
protected static void sleep(long millis) {
if (ShadowApplication.getInstance() == null) {
return;
}
nanoTime = millis * MILLIS_PER_NANO;
ShadowApplication.getInstance().getForegroundThreadScheduler().advanceBy(millis);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testStop() {
shadowMediaPlayer.setState(PREPARED);
mediaPlayer.start();
scheduler.advanceBy(300);
mediaPlayer.stop();
assertThat(mediaPlayer.getCurrentPosition()).isEqualTo(300);
scheduler.advanceBy(400);
assertThat(mediaPlayer.getCurrentPosition()).isEqualTo(300);
}
代码示例来源:origin: robolectric/robolectric
@Config(minSdk = O)
@Test
public void testSeekToMode() {
shadowMediaPlayer.setState(PREPARED);
// This time offset is just to make sure that it doesn't work by
// accident because the offsets are calculated relative to 0.
scheduler.advanceBy(100);
mediaPlayer.start();
scheduler.advanceBy(400);
assertThat(mediaPlayer.getCurrentPosition()).isEqualTo(400);
mediaPlayer.seekTo(600, MediaPlayer.SEEK_CLOSEST);
scheduler.advanceBy(0);
assertThat(mediaPlayer.getCurrentPosition()).isEqualTo(600);
}
代码示例来源: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 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 postDelayed_addsAJobToBeRunInTheFuture() throws Exception {
scheduler.postDelayed(new AddToTranscript("one"), 1000);
scheduler.postDelayed(new AddToTranscript("two"), 2000);
scheduler.postDelayed(new AddToTranscript("three"), 3000);
scheduler.advanceBy(1000);
assertThat(transcript).containsExactly("one");
transcript.clear();
scheduler.advanceBy(500);
assertThat(transcript).isEmpty();
scheduler.advanceBy(501);
assertThat(transcript).containsExactly("two");
transcript.clear();
scheduler.advanceBy(999);
assertThat(transcript).containsExactly("three");
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testPauseUpdatesPosition() {
shadowMediaPlayer.setState(PREPARED);
mediaPlayer.start();
scheduler.advanceBy(200);
mediaPlayer.pause();
scheduler.advanceBy(200);
assertThat(shadowMediaPlayer.getState()).isEqualTo(PAUSED);
assertThat(shadowMediaPlayer.getCurrentPosition()).isEqualTo(200);
mediaPlayer.start();
scheduler.advanceBy(200);
assertThat(shadowMediaPlayer.getState()).isEqualTo(STARTED);
assertThat(shadowMediaPlayer.getCurrentPosition()).isEqualTo(400);
}
代码示例来源: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 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 advanceBy_returnsTrueIffSomeJobWasRun() throws Exception {
scheduler.postDelayed(new AddToTranscript("one"), 0);
scheduler.postDelayed(new AddToTranscript("two"), 0);
scheduler.postDelayed(new AddToTranscript("three"), 1000);
assertThat(scheduler.advanceBy(0)).isTrue();
assertThat(transcript).containsExactly("one", "two");
transcript.clear();
assertThat(scheduler.advanceBy(0)).isFalse();
assertThat(transcript).isEmpty();
assertThat(scheduler.advanceBy(1000)).isTrue();
assertThat(transcript).containsExactly("three");
}
代码示例来源: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();
}
代码示例来源:origin: robolectric/robolectric
@Test
public void shouldRemovePostedCallbacksFromMessageQueue() throws Exception {
TestRunnable runnable = new TestRunnable();
view.postDelayed(runnable, 1);
view.removeCallbacks(runnable);
Robolectric.getForegroundThreadScheduler().advanceBy(1);
assertThat(runnable.wasRun).isFalse();
}
代码示例来源: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 testDoStartStop() {
assertThat(shadowMediaPlayer.isReallyPlaying()).isFalse();
scheduler.advanceBy(100);
shadowMediaPlayer.doStart();
assertThat(shadowMediaPlayer.isReallyPlaying()).isTrue();
assertThat(shadowMediaPlayer.getCurrentPositionRaw()).isEqualTo(0);
assertThat(shadowMediaPlayer.getState()).isSameAs(IDLE);
scheduler.advanceBy(100);
assertThat(shadowMediaPlayer.getCurrentPositionRaw()).isEqualTo(100);
shadowMediaPlayer.doStop();
assertThat(shadowMediaPlayer.isReallyPlaying()).isFalse();
assertThat(shadowMediaPlayer.getCurrentPositionRaw()).isEqualTo(100);
assertThat(shadowMediaPlayer.getState()).isSameAs(IDLE);
scheduler.advanceBy(50);
assertThat(shadowMediaPlayer.getCurrentPositionRaw()).isEqualTo(100);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testSetLoopingCalledWhileStartable() {
final State[] startableStates = { PREPARED, PAUSED };
for (State state : startableStates) {
shadowMediaPlayer.setCurrentPosition(500);
shadowMediaPlayer.setState(state);
mediaPlayer.setLooping(true);
mediaPlayer.start();
scheduler.advanceBy(700);
Mockito.verifyZeroInteractions(completionListener);
assertThat(mediaPlayer.getCurrentPosition()).named(state.toString())
.isEqualTo(200);
}
}
代码示例来源:origin: robolectric/robolectric
@Test
public void shouldPostActionsToTheMessageQueueWithDelay() throws Exception {
ShadowLooper.pauseMainLooper();
TestRunnable runnable = new TestRunnable();
view.postDelayed(runnable, 1);
assertFalse(runnable.wasRun);
Robolectric.getForegroundThreadScheduler().advanceBy(1);
assertTrue(runnable.wasRun);
}
内容来源于网络,如有侵权,请联系作者删除!