本文整理了Java中org.robolectric.util.Scheduler.size()
方法的一些代码示例,展示了Scheduler.size()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Scheduler.size()
方法的具体详情如下:
包路径:org.robolectric.util.Scheduler
类名称:Scheduler
方法名:size
[英]Return the number of enqueued runnables.
[中]返回排队的可运行项的数量。
代码示例来源:origin: robolectric/robolectric
@Test
public void testReleaseStopsScheduler() {
shadowMediaPlayer.doStart();
mediaPlayer.release();
assertThat(scheduler.size()).isEqualTo(0);
}
代码示例来源:origin: robolectric/robolectric
private void recycle_shouldRemoveMessageFromScheduler() {
ShadowLooper.pauseMainLooper();
Handler h = new Handler();
Message msg = Message.obtain(h, 234);
msg.sendToTarget();
Scheduler scheduler = Robolectric.getForegroundThreadScheduler();
assertThat(scheduler.size()).named("before recycle").isEqualTo(1);
shadowOf(msg).recycleUnchecked();
assertThat(scheduler.size()).named("after recycle").isEqualTo(0);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testReleaseCancelsSeekCallback() {
shadowMediaPlayer.setState(STARTED);
mediaPlayer.seekTo(100);
MediaEvent e = Mockito.mock(MediaEvent.class);
shadowMediaPlayer.postEventDelayed(e, 200);
mediaPlayer.release();
assertThat(scheduler.size()).isEqualTo(0);
}
代码示例来源: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 testResetStopsScheduler() {
shadowMediaPlayer.doStart();
mediaPlayer.reset();
assertThat(scheduler.size()).isEqualTo(0);
}
代码示例来源: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 sendBroadcast_shouldSendIntentUsingHandlerIfOneIsProvided() {
HandlerThread handlerThread = new HandlerThread("test");
handlerThread.start();
Handler handler = new Handler(handlerThread.getLooper());
assertNotSame(handler.getLooper(), Looper.getMainLooper());
BroadcastReceiver receiver = broadcastReceiver("Larry");
contextWrapper.registerReceiver(receiver, intentFilter("foo", "baz"), null, handler);
assertThat(shadowOf(handler.getLooper()).getScheduler().size()).isEqualTo(0);
contextWrapper.sendBroadcast(new Intent("foo"));
assertThat(shadowOf(handler.getLooper()).getScheduler().size()).isEqualTo(1);
shadowOf(handlerThread.getLooper()).idle();
assertThat(shadowOf(handler.getLooper()).getScheduler().size()).isEqualTo(0);
assertThat(transcript).containsExactly("Larry notified of foo");
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testResetCancelsCallbacks() {
shadowMediaPlayer.setState(STARTED);
mediaPlayer.seekTo(100);
MediaEvent e = Mockito.mock(MediaEvent.class);
shadowMediaPlayer.postEventDelayed(e, 200);
mediaPlayer.reset();
assertThat(scheduler.size()).isEqualTo(0);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void enqueueMessage_doesntSchedule_whenQuitting() {
setField(queue, quitField, true);
enqueueMessage(testMessage, 1);
assertThat(scheduler.size()).named("scheduler_size").isEqualTo(0);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void nestedPost_whileUnpaused_automaticallyExecutes3After() {
final List<Integer> order = new ArrayList<>();
scheduler.unPause();
scheduler.postDelayed(new Runnable() {
@Override
public void run() {
order.add(1);
scheduler.post(new Runnable() {
@Override
public void run() {
order.add(3);
}
});
order.add(2);
}
}, 0);
assertThat(order).named("order").containsExactly(1, 2, 3);
assertThat(scheduler.size()).named("size").isEqualTo(0);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void nestedPostAtFront_whileUnpaused_runsAfter() {
final List<Integer> order = new ArrayList<>();
scheduler.unPause();
scheduler.postDelayed(new Runnable() {
@Override
public void run() {
order.add(1);
scheduler.postAtFrontOfQueue(new Runnable() {
@Override
public void run() {
order.add(3);
}
});
order.add(2);
}
}, 0);
assertThat(order).named("order").containsExactly(1, 2, 3);
assertThat(scheduler.size()).named("size").isEqualTo(0);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void resetThreadLoopers_resets_background_thread_schedulers() {
HandlerThread backgroundThread = new HandlerThread("resetTest");
backgroundThread.start();
Looper backgroundLooper = backgroundThread.getLooper();
Handler handler = new Handler(backgroundLooper);
Runnable empty = new Runnable() {
@Override
public void run() {}
};
// There should be at least two iterations of this loop because resetThreadLoopers calls
// 'quit' on background loopers once, which also resets the scheduler.
for (int i = 0; i < 5; i++) {
assertThat(shadowOf(backgroundLooper).getScheduler().size()).isEqualTo(0);
assertThat(shadowOf(backgroundLooper).getScheduler().getCurrentTime()).isEqualTo(100L);
handler.post(empty);
handler.postDelayed(empty, 5000);
// increment scheduler's time by 5000
shadowOf(backgroundLooper).runToEndOfTasks();
assertThat(shadowOf(backgroundLooper).getScheduler().getCurrentTime()).isEqualTo(5100L);
ShadowLooper.resetThreadLoopers();
}
}
代码示例来源:origin: robolectric/robolectric
@Test
public void nestedPostDelayed_whileUnpaused_doesntAutomaticallyExecute3() {
final List<Integer> order = new ArrayList<>();
scheduler.unPause();
scheduler.postDelayed(new Runnable() {
@Override
public void run() {
order.add(1);
scheduler.postDelayed(new Runnable() {
@Override
public void run() {
order.add(3);
}
}, 1);
order.add(2);
}
}, 0);
assertThat(order).named("order:before").containsExactly(1, 2);
assertThat(scheduler.size()).named("size:before").isEqualTo(1);
scheduler.advanceToLastPostedRunnable();
assertThat(order).named("order:after").containsExactly(1, 2, 3);
assertThat(scheduler.size()).named("size:after").isEqualTo(0);
assertThat(scheduler.getCurrentTime()).named("time:after").isEqualTo(1 + startTime);
}
代码示例来源:origin: robolectric/robolectric
assertThat(scheduler.size()).named("size:first run").isEqualTo(2);
scheduler.runOneTask();
assertThat(order).named("order:second run").containsExactly(1, 2, 3);
assertThat(scheduler.size()).named("size:second run").isEqualTo(1);
scheduler.runOneTask();
assertThat(order).named("order:third run").containsExactly(1, 2, 3, 4);
assertThat(scheduler.size()).named("size:second run").isEqualTo(0);
代码示例来源:origin: robolectric/robolectric
@Test
public void nestedPostAtFront_whilePaused_runsBeforeSubsequentPost() {
final List<Integer> order = new ArrayList<>();
scheduler.postDelayed(new Runnable() {
@Override
public void run() {
order.add(1);
scheduler.postAtFrontOfQueue(new Runnable() {
@Override
public void run() {
order.add(3);
}
});
order.add(2);
}
}, 0);
scheduler.postDelayed(new Runnable() {
@Override
public void run() {
order.add(4);
}
}, 0);
scheduler.advanceToLastPostedRunnable();
assertThat(order).named("order").containsExactly(1, 2, 3, 4);
assertThat(scheduler.size()).named("size").isEqualTo(0);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void nestedPostDelayed_whenIdlingConstantly_automaticallyExecutes3After() {
final List<Integer> order = new ArrayList<>();
scheduler.setIdleState(CONSTANT_IDLE);
scheduler.postDelayed(new Runnable() {
@Override
public void run() {
order.add(1);
scheduler.postDelayed(new Runnable() {
@Override
public void run() {
order.add(3);
}
}, 1);
order.add(2);
}
}, 0);
assertThat(order).named("order").containsExactly(1, 2, 3);
assertThat(scheduler.size()).named("size").isEqualTo(0);
assertThat(scheduler.getCurrentTime()).named("time").isEqualTo(1 + startTime);
}
代码示例来源:origin: robolectric/robolectric
assertThat(scheduler.size()).isEqualTo(1);
shadowMediaPlayer.doStop();
info.scheduleInfoAtOffset(250, 2, 4);
shadowMediaPlayer.doStart();
assertThat(scheduler.size()).isEqualTo(1);
assertThat(scheduler.size()).isEqualTo(0);
scheduler.advanceBy(324);
MediaEvent e2 = Mockito.mock(MediaEvent.class);
assertThat(scheduler.size()).isEqualTo(0);
assertThat(shadowMediaPlayer.getCurrentPositionRaw()).isEqualTo(675);
assertThat(shadowMediaPlayer.getState()).isSameAs(ERROR);
代码示例来源:origin: org.robolectric/robolectric-utils
/**
* Run all runnables in the queue.
*
* @return True if a runnable was executed.
*/
public synchronized boolean advanceToLastPostedRunnable() {
return size() >= 1 && advanceTo(runnables.get(runnables.size() - 1).scheduledTime);
}
代码示例来源:origin: org.robolectric/robolectric-utils
/**
* Run the next runnable in the queue.
*
* @return True if a runnable was executed.
*/
public synchronized boolean advanceToNextPostedRunnable() {
return size() >= 1 && advanceTo(runnables.get(0).scheduledTime);
}
内容来源于网络,如有侵权,请联系作者删除!