本文整理了Java中org.robolectric.util.Scheduler.setIdleState()
方法的一些代码示例,展示了Scheduler.setIdleState()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Scheduler.setIdleState()
方法的具体详情如下:
包路径:org.robolectric.util.Scheduler
类名称:Scheduler
方法名:setIdleState
[英]Sets the current idling state of this Scheduler. If transitioning to the IdleState#UNPAUSED state any tasks scheduled to be run at or before the current time will be run, and if transitioning to the IdleState#CONSTANT_IDLE state all scheduled tasks will be run and the clock advanced to the time of the last runnable.
[中]设置此计划程序的当前空闲状态。如果过渡到IDLState#未暂停状态,计划在当前时间或之前运行的任何任务都将运行,如果过渡到IDLState#恒定35u空闲状态,所有计划任务都将运行,时钟将提前到最后一次可运行的时间。
代码示例来源:origin: robolectric/robolectric
/**
* Pause the scheduler. Equivalent to <tt>setIdleState(PAUSED)</tt>.
*
* @see #unPause()
* @see #setIdleState(IdleState)
*/
public synchronized void pause() {
setIdleState(PAUSED);
}
代码示例来源:origin: robolectric/robolectric
/**
* Un-pause the scheduler. Equivalent to <tt>setIdleState(UNPAUSED)</tt>.
*
* @see #pause()
* @see #setIdleState(IdleState)
*/
public synchronized void unPause() {
setIdleState(UNPAUSED);
}
代码示例来源:origin: robolectric/robolectric
/**
* Set the idle state of the Scheduler. If necessary, the clock will be advanced and runnables
* executed as required by the newly-set state.
*
* @param shouldIdleConstantly If <tt>true</tt> the idle state will be set to
* {@link IdleState#CONSTANT_IDLE}, otherwise it will be set to
* {@link IdleState#UNPAUSED}.
* @deprecated This method is ambiguous in how it should behave when turning off constant idle.
* Use {@link #setIdleState(IdleState)} instead to explicitly set the state.
*/
@Deprecated
public void idleConstantly(boolean shouldIdleConstantly) {
setIdleState(shouldIdleConstantly ? CONSTANT_IDLE : UNPAUSED);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void whenIdleStateIsUnPaused_isPausedReturnsFalse() {
scheduler.setIdleState(UNPAUSED);
assertThat(scheduler.isPaused()).isFalse();
}
代码示例来源:origin: robolectric/robolectric
@Test
public void whenIdleStateIsConstantIdle_isPausedReturnsFalse() {
scheduler.setIdleState(CONSTANT_IDLE);
assertThat(scheduler.isPaused()).isFalse();
}
代码示例来源:origin: robolectric/robolectric
@Test
public void whenIdleStateIsPaused_isPausedReturnsTrue() {
scheduler.setIdleState(PAUSED);
assertThat(scheduler.isPaused()).isTrue();
}
代码示例来源:origin: robolectric/robolectric
@Test
public void pause_setsIdleState() {
scheduler.setIdleState(UNPAUSED);
scheduler.pause();
assertThat(scheduler.getIdleState()).isSameAs(PAUSED);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void unPause_setsIdleState() {
scheduler.setIdleState(PAUSED);
scheduler.unPause();
assertThat(scheduler.getIdleState()).isSameAs(UNPAUSED);
}
代码示例来源:origin: robolectric/robolectric
@Test
public void postDelayed_whileIdlingConstantly_executesImmediately() {
scheduler.setIdleState(CONSTANT_IDLE);
scheduler.postDelayed(new AddToTranscript("one"), 1000);
assertThat(transcript).containsExactly("one");
}
代码示例来源: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
@SuppressWarnings("deprecation")
public void idleConstantly_setsIdleState() {
scheduler.setIdleState(UNPAUSED);
scheduler.idleConstantly(true);
assertThat(scheduler.getIdleState()).isSameAs(CONSTANT_IDLE);
scheduler.idleConstantly(false);
assertThat(scheduler.getIdleState()).isSameAs(UNPAUSED);
}
代码示例来源: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
@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
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: org.robolectric/utils
/**
* Pause the scheduler. Equivalent to <tt>setIdleState(PAUSED)</tt>.
*
* @see #unPause()
* @see #setIdleState(IdleState)
*/
public synchronized void pause() {
setIdleState(PAUSED);
}
代码示例来源:origin: org.robolectric/utils
/**
* Un-pause the scheduler. Equivalent to <tt>setIdleState(UNPAUSED)</tt>.
*
* @see #pause()
* @see #setIdleState(IdleState)
*/
public synchronized void unPause() {
setIdleState(UNPAUSED);
}
代码示例来源:origin: org.robolectric/robolectric-utils
/**
* Pause the scheduler. Equivalent to <tt>setIdleState(PAUSED)</tt>.
*
* @see #unPause()
* @see #setIdleState(IdleState)
*/
public synchronized void pause() {
setIdleState(PAUSED);
}
代码示例来源:origin: org.robolectric/robolectric-utils
/**
* Un-pause the scheduler. Equivalent to <tt>setIdleState(UNPAUSED)</tt>.
*
* @see #pause()
* @see #setIdleState(IdleState)
*/
public synchronized void unPause() {
setIdleState(UNPAUSED);
}
代码示例来源:origin: org.robolectric/robolectric-utils
/**
* Set the idle state of the Scheduler. If necessary, the clock will be advanced and runnables
* executed as required by the newly-set state.
*
* @param shouldIdleConstantly If <tt>true</tt> the idle state will be set to
* {@link IdleState#CONSTANT_IDLE}, otherwise it will be set to
* {@link IdleState#UNPAUSED}.
* @deprecated This method is ambiguous in how it should behave when turning off constant idle.
* Use {@link #setIdleState(IdleState)} instead to explicitly set the state.
*/
@Deprecated
public void idleConstantly(boolean shouldIdleConstantly) {
setIdleState(shouldIdleConstantly ? CONSTANT_IDLE : UNPAUSED);
}
代码示例来源:origin: org.robolectric/utils
/**
* Set the idle state of the Scheduler. If necessary, the clock will be advanced and runnables
* executed as required by the newly-set state.
*
* @param shouldIdleConstantly If <tt>true</tt> the idle state will be set to
* {@link IdleState#CONSTANT_IDLE}, otherwise it will be set to
* {@link IdleState#UNPAUSED}.
* @deprecated This method is ambiguous in how it should behave when turning off constant idle.
* Use {@link #setIdleState(IdleState)} instead to explicitly set the state.
*/
@Deprecated
public void idleConstantly(boolean shouldIdleConstantly) {
setIdleState(shouldIdleConstantly ? CONSTANT_IDLE : UNPAUSED);
}
内容来源于网络,如有侵权,请联系作者删除!