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

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

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

Scheduler.advanceTo介绍

[英]Run all runnables that are scheduled before the endTime.
[中]运行在结束时间之前计划的所有可运行程序。

代码示例

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

/**
 * Run all runnables in the queue, and any additional runnables they schedule that are scheduled
 * before the latest scheduled runnable currently in the queue.
 *
 * @return True if a runnable was executed.
 */
public synchronized boolean advanceToLastPostedRunnable() {
 long currentMaxTime = currentTime;
 for (ScheduledRunnable scheduled : runnables) {
  if (currentMaxTime < scheduled.scheduledTime) {
   currentMaxTime = scheduled.scheduledTime;
  }
 }
 return advanceTo(currentMaxTime);
}

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

/**
 * Run all runnables that are scheduled to run in the next time interval.
 *
 * @return  True if a runnable was executed.
 */
public synchronized boolean advanceBy(long amount, TimeUnit unit) {
 long endingTime = currentTime + unit.toMillis(amount);
 return advanceTo(endingTime);
}

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

/**
 * Run the next runnable in the queue.
 *
 * @return  True if a runnable was executed.
 */
public synchronized boolean advanceToNextPostedRunnable() {
 return !runnables.isEmpty() && advanceTo(runnables.peek().scheduledTime);
}

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

@Implementation
protected static boolean setCurrentTimeMillis(long millis) {
 if (ShadowApplication.getInstance() == null) {
  return false;
 }
 if (now() > millis) {
  return false;
 }
 nanoTime = millis * MILLIS_PER_NANO;
 ShadowApplication.getInstance().getForegroundThreadScheduler().advanceTo(millis);
 return true;
}

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

@Test
public void testElapsedRealtime() {
 Robolectric.getForegroundThreadScheduler().advanceTo(1000);
 assertThat(SystemClock.elapsedRealtime()).isEqualTo(1000);
 Robolectric.getForegroundThreadScheduler().advanceTo(1034);
 assertThat(SystemClock.elapsedRealtime()).isEqualTo(1034);
}

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

@Test
public void sleep() {
 Robolectric.getForegroundThreadScheduler().advanceTo(1000);
 SystemClock.sleep(34);
 assertThat(SystemClock.uptimeMillis()).isEqualTo(1034);
}

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

@Test
public void shouldAllowForFakingOfTime() throws Exception {
 assertThat(SystemClock.uptimeMillis()).isNotEqualTo(1000);
 Robolectric.getForegroundThreadScheduler().advanceTo(1000);
 assertThat(SystemClock.uptimeMillis()).isEqualTo(1000);
}

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

@Test
public void enqueuedMessage_isSentToHandler() {
 enqueueMessage(testMessage, 200);
 scheduler.advanceTo(199);
 assertThat(handler.handled).named("handled:before").isEmpty();
 scheduler.advanceTo(200);
 assertThat(handler.handled).named("handled:after").containsExactly(testMessage);
}

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

@Test
public void advanceTo_shouldAdvanceTimeEvenIfThereIsNoWork() throws Exception {
 scheduler.advanceTo(1000);
 assertThat(scheduler.getCurrentTime()).isEqualTo(1000);
}

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

@Test @Config(minSdk = JELLY_BEAN_MR1)
public void testElapsedRealtimeNanos() {
 Robolectric.getForegroundThreadScheduler().advanceTo(1000);
 assertThat(SystemClock.elapsedRealtimeNanos()).isEqualTo(1000000000);
 Robolectric.getForegroundThreadScheduler().advanceTo(1034);
 assertThat(SystemClock.elapsedRealtimeNanos()).isEqualTo(1034000000);
}

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

@Test
public void testSetCurrentTime() {
 Robolectric.getForegroundThreadScheduler().advanceTo(1000);
 assertThat(ShadowSystemClock.now()).isEqualTo(1000);
 assertTrue(SystemClock.setCurrentTimeMillis(1034));
 assertThat(ShadowSystemClock.now()).isEqualTo(1034);
 assertFalse(SystemClock.setCurrentTimeMillis(1000));
 assertThat(ShadowSystemClock.now()).isEqualTo(1034);
}

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

/**
 * Run all runnables that are scheduled to run in the next time interval.
 *
 * @return  True if a runnable was executed.
 */
public synchronized boolean advanceBy(long amount, TimeUnit unit) {
 long endingTime = currentTime + unit.toMillis(amount);
 return advanceTo(endingTime);
}

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

/**
 * Run all runnables that are scheduled to run in the next time interval.
 *
 * @return  True if a runnable was executed.
 */
public synchronized boolean advanceBy(long amount, TimeUnit unit) {
 long endingTime = currentTime + unit.toMillis(amount);
 return advanceTo(endingTime);
}

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

/**
 * Run the next runnable in the queue.
 *
 * @return  True if a runnable was executed.
 */
public synchronized boolean advanceToNextPostedRunnable() {
 return !runnables.isEmpty() && advanceTo(runnables.peek().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);
}

代码示例来源: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/shadows-core-v23

@Implementation
public static boolean setCurrentTimeMillis(long millis) {
 if (ShadowApplication.getInstance() == null) {
  return false;
 }
 if (now() > millis) {
  return false;
 }
 nanoTime = millis * MILLIS_PER_NANO;
 ShadowApplication.getInstance().getForegroundThreadScheduler().advanceTo(millis);
 return true;
}

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

@Implementation
public static boolean setCurrentTimeMillis(long millis) {
 if (ShadowApplication.getInstance() == null) {
  return false;
 }
 if (now() > millis) {
  return false;
 }
 nanoTime = millis * MILLIS_PER_NANO;
 ShadowApplication.getInstance().getForegroundThreadScheduler().advanceTo(millis);
 return true;
}

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

@Implementation
public static boolean setCurrentTimeMillis(long millis) {
 if (ShadowApplication.getInstance() == null) {
  return false;
 }
 if (now() > millis) {
  return false;
 }
 nanoTime = millis * MILLIS_PER_NANO;
 ShadowApplication.getInstance().getForegroundThreadScheduler().advanceTo(millis);
 return true;
}

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

@Implementation
protected static boolean setCurrentTimeMillis(long millis) {
 if (ShadowApplication.getInstance() == null) {
  return false;
 }
 if (now() > millis) {
  return false;
 }
 nanoTime = millis * MILLIS_PER_NANO;
 ShadowApplication.getInstance().getForegroundThreadScheduler().advanceTo(millis);
 return true;
}

相关文章