本文整理了Java中org.robolectric.util.Scheduler.getCurrentTime()
方法的一些代码示例,展示了Scheduler.getCurrentTime()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Scheduler.getCurrentTime()
方法的具体详情如下:
包路径:org.robolectric.util.Scheduler
类名称:Scheduler
方法名:getCurrentTime
[英]Get the current time (as seen by the scheduler), in milliseconds.
[中]获取当前时间(如调度程序所示),以毫秒为单位。
代码示例来源:origin: robolectric/robolectric
@Override
public void run() {
observedTime[0] = scheduler.getCurrentTime();
}
},
代码示例来源:origin: robolectric/robolectric
private long deltaTime() {
return getScheduler().getCurrentTime() - startTime;
}
代码示例来源:origin: robolectric/robolectric
@Override
public void run() {
l.set(scheduler.getCurrentTime());
}
};
代码示例来源:origin: robolectric/robolectric
private long deltaTime() {
return ShadowApplication.getInstance().getForegroundThreadScheduler().getCurrentTime() - startTime;
}
代码示例来源:origin: robolectric/robolectric
static long now() {
if (ShadowApplication.getInstance() == null) {
return 0;
}
return ShadowApplication.getInstance().getForegroundThreadScheduler().getCurrentTime();
}
代码示例来源:origin: robolectric/robolectric
@Override
public void handleMessage(Message msg) {
runAt.add(shadowOf(Looper.myLooper()).getScheduler().getCurrentTime());
}
};
代码示例来源:origin: robolectric/robolectric
@Before
public void setUp() throws Exception {
scheduler.pause();
startTime = scheduler.getCurrentTime();
}
代码示例来源:origin: robolectric/robolectric
@Test
public void testPrepare() throws IOException {
int[] testDelays = { 0, 10, 100, 1500 };
for (int delay : testDelays) {
final long startTime = scheduler.getCurrentTime();
info.setPreparationDelay(delay);
shadowMediaPlayer.setState(INITIALIZED);
mediaPlayer.prepare();
assertThat(shadowMediaPlayer.getState()).isEqualTo(PREPARED);
assertThat(scheduler.getCurrentTime()).isEqualTo(startTime + delay);
}
}
代码示例来源:origin: robolectric/robolectric
@Test
public void advanceTo_shouldAdvanceTimeEvenIfThereIsNoWork() throws Exception {
scheduler.advanceTo(1000);
assertThat(scheduler.getCurrentTime()).isEqualTo(1000);
}
代码示例来源: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 pendingTasks_areRunEagerly_whenActivityIsStarted_andSchedulerUnPaused() {
final Scheduler s = Robolectric.getForegroundThreadScheduler();
final long startTime = s.getCurrentTime();
TestDelayedPostActivity activity = Robolectric.setupActivity(TestDelayedPostActivity.class);
assertThat(activity.r1.wasRun).named("immediate task").isTrue();
assertThat(s.getCurrentTime()).named("currentTime").isEqualTo(startTime);
}
代码示例来源:origin: google/agera
@Test
public void shouldUpdatePerMillisecondObservable() {
final long expectedDelayedTime = scheduler.getCurrentTime() + FILTER_TIME;
updatable.addToObservable(perMillisecondObservable(FILTER_TIME, updateDispatcher));
updateDispatcher.update();
idleMainLooper(FILTER_TIME);
assertThat(updatable, wasUpdated());
assertThat(scheduler.getCurrentTime(), greaterThanOrEqualTo(expectedDelayedTime));
}
代码示例来源: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: google/agera
@Test
public void shouldUpdateCompositeOfSinglePerMillisecondObservable() {
final long expectedDelayedTime = scheduler.getCurrentTime() + FILTER_TIME;
updatable.addToObservable(compositeObservable(perMillisecondObservable(
FILTER_TIME, updateDispatcher)));
updateDispatcher.update();
idleMainLooper(FILTER_TIME);
assertThat(updatable, wasUpdated());
assertThat(scheduler.getCurrentTime(), greaterThanOrEqualTo(expectedDelayedTime));
}
代码示例来源:origin: google/agera
@Test
public void shouldUpdateCompositeOfPerMillisecondObservable() {
final long expectedDelayedTime = scheduler.getCurrentTime() + FILTER_TIME;
updatable.addToObservable(compositeObservable(perMillisecondObservable(
FILTER_TIME, updateDispatcher), updateDispatcher()));
updateDispatcher.update();
idleMainLooper(FILTER_TIME);
assertThat(updatable, wasUpdated());
assertThat(scheduler.getCurrentTime(), greaterThanOrEqualTo(expectedDelayedTime));
}
代码示例来源:origin: robolectric/robolectric
@Test
public void postDelayed_whileIdlingConstantly_advancesTime() {
scheduler.setIdleState(CONSTANT_IDLE);
scheduler.postDelayed(new AddToTranscript("one"), 1000);
assertThat(scheduler.getCurrentTime()).isEqualTo(1000 + startTime);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void unPause_shouldRunPendingTasks() {
scheduler.postDelayed(new AddToTranscript("one"), 0);
scheduler.postDelayed(new AddToTranscript("two"), 0);
scheduler.postDelayed(new AddToTranscript("three"), 1000);
assertThat(transcript).isEmpty();
final long time = scheduler.getCurrentTime();
scheduler.unPause();
assertThat(transcript).containsExactly("one", "two");
assertThat(scheduler.getCurrentTime()).named("time").isEqualTo(time);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void setIdleStateToConstantIdle_shouldRunAllTasks() {
scheduler.postDelayed(new AddToTranscript("one"), 0);
scheduler.postDelayed(new AddToTranscript("two"), 0);
scheduler.postDelayed(new AddToTranscript("three"), 1000);
assertThat(transcript).isEmpty();
final long time = scheduler.getCurrentTime();
scheduler.setIdleState(CONSTANT_IDLE);
assertThat(transcript).containsExactly("one", "two", "three");
assertThat(scheduler.getCurrentTime()).named("time").isEqualTo(time + 1000);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void setIdleStateToUnPause_shouldRunPendingTasks() {
scheduler.postDelayed(new AddToTranscript("one"), 0);
scheduler.postDelayed(new AddToTranscript("two"), 0);
scheduler.postDelayed(new AddToTranscript("three"), 1000);
assertThat(transcript).isEmpty();
final long time = scheduler.getCurrentTime();
scheduler.setIdleState(UNPAUSED);
assertThat(transcript).containsExactly("one", "two");
assertThat(scheduler.getCurrentTime()).named("time").isEqualTo(time);
}
代码示例来源:origin: robolectric/robolectric
@Test
@SuppressWarnings("deprecation")
public void idleConstantlyTrue_shouldRunAllTasks() {
scheduler.postDelayed(new AddToTranscript("one"), 0);
scheduler.postDelayed(new AddToTranscript("two"), 0);
scheduler.postDelayed(new AddToTranscript("three"), 1000);
assertThat(transcript).isEmpty();
final long time = scheduler.getCurrentTime();
scheduler.idleConstantly(true);
assertThat(transcript).containsExactly("one", "two", "three");
assertThat(scheduler.getCurrentTime()).named("time").isEqualTo(time + 1000);
}
内容来源于网络,如有侵权,请联系作者删除!