org.robolectric.util.Scheduler.setIdleState()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(7.3k)|赞(0)|评价(0)|浏览(124)

本文整理了Java中org.robolectric.util.Scheduler.setIdleState()方法的一些代码示例,展示了Scheduler.setIdleState()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Scheduler.setIdleState()方法的具体详情如下:
包路径:org.robolectric.util.Scheduler
类名称:Scheduler
方法名:setIdleState

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

  1. /**
  2. * Pause the scheduler. Equivalent to <tt>setIdleState(PAUSED)</tt>.
  3. *
  4. * @see #unPause()
  5. * @see #setIdleState(IdleState)
  6. */
  7. public synchronized void pause() {
  8. setIdleState(PAUSED);
  9. }

代码示例来源:origin: robolectric/robolectric

  1. /**
  2. * Un-pause the scheduler. Equivalent to <tt>setIdleState(UNPAUSED)</tt>.
  3. *
  4. * @see #pause()
  5. * @see #setIdleState(IdleState)
  6. */
  7. public synchronized void unPause() {
  8. setIdleState(UNPAUSED);
  9. }

代码示例来源:origin: robolectric/robolectric

  1. /**
  2. * Set the idle state of the Scheduler. If necessary, the clock will be advanced and runnables
  3. * executed as required by the newly-set state.
  4. *
  5. * @param shouldIdleConstantly If <tt>true</tt> the idle state will be set to
  6. * {@link IdleState#CONSTANT_IDLE}, otherwise it will be set to
  7. * {@link IdleState#UNPAUSED}.
  8. * @deprecated This method is ambiguous in how it should behave when turning off constant idle.
  9. * Use {@link #setIdleState(IdleState)} instead to explicitly set the state.
  10. */
  11. @Deprecated
  12. public void idleConstantly(boolean shouldIdleConstantly) {
  13. setIdleState(shouldIdleConstantly ? CONSTANT_IDLE : UNPAUSED);
  14. }

代码示例来源:origin: robolectric/robolectric

  1. @Test
  2. public void whenIdleStateIsUnPaused_isPausedReturnsFalse() {
  3. scheduler.setIdleState(UNPAUSED);
  4. assertThat(scheduler.isPaused()).isFalse();
  5. }

代码示例来源:origin: robolectric/robolectric

  1. @Test
  2. public void whenIdleStateIsConstantIdle_isPausedReturnsFalse() {
  3. scheduler.setIdleState(CONSTANT_IDLE);
  4. assertThat(scheduler.isPaused()).isFalse();
  5. }

代码示例来源:origin: robolectric/robolectric

  1. @Test
  2. public void whenIdleStateIsPaused_isPausedReturnsTrue() {
  3. scheduler.setIdleState(PAUSED);
  4. assertThat(scheduler.isPaused()).isTrue();
  5. }

代码示例来源:origin: robolectric/robolectric

  1. @Test
  2. public void pause_setsIdleState() {
  3. scheduler.setIdleState(UNPAUSED);
  4. scheduler.pause();
  5. assertThat(scheduler.getIdleState()).isSameAs(PAUSED);
  6. }

代码示例来源:origin: robolectric/robolectric

  1. @Test
  2. public void unPause_setsIdleState() {
  3. scheduler.setIdleState(PAUSED);
  4. scheduler.unPause();
  5. assertThat(scheduler.getIdleState()).isSameAs(UNPAUSED);
  6. }

代码示例来源:origin: robolectric/robolectric

  1. @Test
  2. public void postDelayed_whileIdlingConstantly_executesImmediately() {
  3. scheduler.setIdleState(CONSTANT_IDLE);
  4. scheduler.postDelayed(new AddToTranscript("one"), 1000);
  5. assertThat(transcript).containsExactly("one");
  6. }

代码示例来源:origin: robolectric/robolectric

  1. @Test
  2. public void postDelayed_whileIdlingConstantly_advancesTime() {
  3. scheduler.setIdleState(CONSTANT_IDLE);
  4. scheduler.postDelayed(new AddToTranscript("one"), 1000);
  5. assertThat(scheduler.getCurrentTime()).isEqualTo(1000 + startTime);
  6. }

代码示例来源:origin: robolectric/robolectric

  1. @Test
  2. @SuppressWarnings("deprecation")
  3. public void idleConstantly_setsIdleState() {
  4. scheduler.setIdleState(UNPAUSED);
  5. scheduler.idleConstantly(true);
  6. assertThat(scheduler.getIdleState()).isSameAs(CONSTANT_IDLE);
  7. scheduler.idleConstantly(false);
  8. assertThat(scheduler.getIdleState()).isSameAs(UNPAUSED);
  9. }

代码示例来源:origin: robolectric/robolectric

  1. @Test
  2. public void nestedPostDelayed_whenIdlingConstantly_automaticallyExecutes3After() {
  3. final List<Integer> order = new ArrayList<>();
  4. scheduler.setIdleState(CONSTANT_IDLE);
  5. scheduler.postDelayed(new Runnable() {
  6. @Override
  7. public void run() {
  8. order.add(1);
  9. scheduler.postDelayed(new Runnable() {
  10. @Override
  11. public void run() {
  12. order.add(3);
  13. }
  14. }, 1);
  15. order.add(2);
  16. }
  17. }, 0);
  18. assertThat(order).named("order").containsExactly(1, 2, 3);
  19. assertThat(scheduler.size()).named("size").isEqualTo(0);
  20. assertThat(scheduler.getCurrentTime()).named("time").isEqualTo(1 + startTime);
  21. }

代码示例来源:origin: robolectric/robolectric

  1. @Test
  2. public void setIdleStateToUnPause_shouldRunPendingTasks() {
  3. scheduler.postDelayed(new AddToTranscript("one"), 0);
  4. scheduler.postDelayed(new AddToTranscript("two"), 0);
  5. scheduler.postDelayed(new AddToTranscript("three"), 1000);
  6. assertThat(transcript).isEmpty();
  7. final long time = scheduler.getCurrentTime();
  8. scheduler.setIdleState(UNPAUSED);
  9. assertThat(transcript).containsExactly("one", "two");
  10. assertThat(scheduler.getCurrentTime()).named("time").isEqualTo(time);
  11. }

代码示例来源:origin: robolectric/robolectric

  1. @Test
  2. public void setIdleStateToConstantIdle_shouldRunAllTasks() {
  3. scheduler.postDelayed(new AddToTranscript("one"), 0);
  4. scheduler.postDelayed(new AddToTranscript("two"), 0);
  5. scheduler.postDelayed(new AddToTranscript("three"), 1000);
  6. assertThat(transcript).isEmpty();
  7. final long time = scheduler.getCurrentTime();
  8. scheduler.setIdleState(CONSTANT_IDLE);
  9. assertThat(transcript).containsExactly("one", "two", "three");
  10. assertThat(scheduler.getCurrentTime()).named("time").isEqualTo(time + 1000);
  11. }

代码示例来源:origin: org.robolectric/utils

  1. /**
  2. * Pause the scheduler. Equivalent to <tt>setIdleState(PAUSED)</tt>.
  3. *
  4. * @see #unPause()
  5. * @see #setIdleState(IdleState)
  6. */
  7. public synchronized void pause() {
  8. setIdleState(PAUSED);
  9. }

代码示例来源:origin: org.robolectric/utils

  1. /**
  2. * Un-pause the scheduler. Equivalent to <tt>setIdleState(UNPAUSED)</tt>.
  3. *
  4. * @see #pause()
  5. * @see #setIdleState(IdleState)
  6. */
  7. public synchronized void unPause() {
  8. setIdleState(UNPAUSED);
  9. }

代码示例来源:origin: org.robolectric/robolectric-utils

  1. /**
  2. * Pause the scheduler. Equivalent to <tt>setIdleState(PAUSED)</tt>.
  3. *
  4. * @see #unPause()
  5. * @see #setIdleState(IdleState)
  6. */
  7. public synchronized void pause() {
  8. setIdleState(PAUSED);
  9. }

代码示例来源:origin: org.robolectric/robolectric-utils

  1. /**
  2. * Un-pause the scheduler. Equivalent to <tt>setIdleState(UNPAUSED)</tt>.
  3. *
  4. * @see #pause()
  5. * @see #setIdleState(IdleState)
  6. */
  7. public synchronized void unPause() {
  8. setIdleState(UNPAUSED);
  9. }

代码示例来源:origin: org.robolectric/robolectric-utils

  1. /**
  2. * Set the idle state of the Scheduler. If necessary, the clock will be advanced and runnables
  3. * executed as required by the newly-set state.
  4. *
  5. * @param shouldIdleConstantly If <tt>true</tt> the idle state will be set to
  6. * {@link IdleState#CONSTANT_IDLE}, otherwise it will be set to
  7. * {@link IdleState#UNPAUSED}.
  8. * @deprecated This method is ambiguous in how it should behave when turning off constant idle.
  9. * Use {@link #setIdleState(IdleState)} instead to explicitly set the state.
  10. */
  11. @Deprecated
  12. public void idleConstantly(boolean shouldIdleConstantly) {
  13. setIdleState(shouldIdleConstantly ? CONSTANT_IDLE : UNPAUSED);
  14. }

代码示例来源:origin: org.robolectric/utils

  1. /**
  2. * Set the idle state of the Scheduler. If necessary, the clock will be advanced and runnables
  3. * executed as required by the newly-set state.
  4. *
  5. * @param shouldIdleConstantly If <tt>true</tt> the idle state will be set to
  6. * {@link IdleState#CONSTANT_IDLE}, otherwise it will be set to
  7. * {@link IdleState#UNPAUSED}.
  8. * @deprecated This method is ambiguous in how it should behave when turning off constant idle.
  9. * Use {@link #setIdleState(IdleState)} instead to explicitly set the state.
  10. */
  11. @Deprecated
  12. public void idleConstantly(boolean shouldIdleConstantly) {
  13. setIdleState(shouldIdleConstantly ? CONSTANT_IDLE : UNPAUSED);
  14. }

相关文章