本文整理汇总了Java中org.robolectric.util.Scheduler类的典型用法代码示例。如果您正苦于以下问题:Java Scheduler类的具体用法?Java Scheduler怎么用?Java Scheduler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Scheduler类属于org.robolectric.util包,在下文中一共展示了Scheduler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: cancelBeforeNextLooperCycle
import org.robolectric.util.Scheduler; //导入依赖的package包/类
@Test
public void cancelBeforeNextLooperCycle() {
final Scheduler scheduler = Robolectric.getForegroundThreadScheduler();
scheduler.pause();
final AnimatorContext testContext = spy(new AnimatorContext("Test"));
final MultiAnimator animator = MultiAnimator.animatorFor(fakeView, testContext);
animator.translationY(0f);
animator.start();
verify(testContext).beginAnimation(any(String.class));
animator.cancel();
verify(testContext).endAnimation(any(String.class));
}
示例2: end
import org.robolectric.util.Scheduler; //导入依赖的package包/类
@Test
public void end() {
final Scheduler scheduler = Robolectric.getForegroundThreadScheduler();
scheduler.pause();
final AnimatorContext testContext = spy(new AnimatorContext("Test"));
final MultiAnimator animator = MultiAnimator.animatorFor(fakeView, testContext);
animator.translationY(100f);
final Animator.AnimatorListener listener = mock(Animator.AnimatorListener.class);
animator.addListener(listener);
animator.start();
verify(testContext).beginAnimation(any(String.class));
animator.end();
verify(testContext).endAnimation(any(String.class));
verify(listener, never()).onAnimationCancel(animator);
verify(listener).onAnimationEnd(animator);
assertThat(fakeView.getTranslationY(), is(equalTo(100f)));
assertThat(animator.isRunning(), is(false));
}
示例3: serialization
import org.robolectric.util.Scheduler; //导入依赖的package包/类
@Test
public void serialization() {
final Scheduler scheduler = Robolectric.getForegroundThreadScheduler();
scheduler.pause();
powerUpTimer.schedulePowerUp(PowerUp.SLOW_DOWN_TIME, CountUp.NUMBER_TICKS);
assertThat(powerUpTimer.isPending(PowerUp.SLOW_DOWN_TIME), is(true));
final Bundle savedState = new Bundle();
powerUpTimer.saveState(savedState);
final PowerUpTimer restored = new PowerUpTimer(bus);
restored.restoreState(savedState);
assertThat(restored.isPending(PowerUp.SLOW_DOWN_TIME), is(true));
assertThat(restored.isPending(PowerUp.MULTIPLY_SCORE), is(false));
assertThat(restored.isPending(PowerUp.CLEAR_ALL), is(false));
}
示例4: multiplyScore
import org.robolectric.util.Scheduler; //导入依赖的package包/类
@Test
public void multiplyScore() {
final Scheduler scheduler = Robolectric.getForegroundThreadScheduler();
scheduler.pause();
game.newGame();
assertThat(game.multiplyScore(), is(false));
game.board.addPowerUp(PowerUp.MULTIPLY_SCORE);
assertThat(game.multiplyScore(), is(true));
assertThat(game.multiplyScore(), is(false));
assertThat(game.powerUpTimer.isPending(PowerUp.MULTIPLY_SCORE), is(true));
assertThat(game.score.getMultiplier(), is(equalTo(2f)));
scheduler.advanceBy(PowerUpTimer.TICK_DURATION_MS * PowerUpTimer.STANDARD_NUMBER_TICKS);
assertThat(game.powerUpTimer.isPending(PowerUp.MULTIPLY_SCORE), is(false));
assertThat(game.score.getMultiplier(), is(equalTo(1f)));
}
示例5: slowDownTime
import org.robolectric.util.Scheduler; //导入依赖的package包/类
@Test
public void slowDownTime() {
final Scheduler scheduler = Robolectric.getForegroundThreadScheduler();
scheduler.pause();
game.newGame();
assertThat(game.slowDownTime(), is(false));
game.board.addPowerUp(PowerUp.SLOW_DOWN_TIME);
assertThat(game.slowDownTime(), is(true));
assertThat(game.slowDownTime(), is(false));
assertThat(game.powerUpTimer.isPending(PowerUp.SLOW_DOWN_TIME), is(true));
assertThat(game.countUp.getTickDurationMs(), is(equalTo(2000L)));
scheduler.advanceBy(PowerUpTimer.TICK_DURATION_MS * PowerUpTimer.STANDARD_NUMBER_TICKS);
assertThat(game.powerUpTimer.isPending(PowerUp.SLOW_DOWN_TIME), is(false));
assertThat(game.countUp.getTickDurationMs(), is(not(equalTo(2000L))));
}
示例6: basicCountDown
import org.robolectric.util.Scheduler; //导入依赖的package包/类
@Test
public void basicCountDown() {
final CountUp countUp = new CountUp(bus);
assertThat(countUp.isRunning(), is(false));
final Scheduler scheduler = Robolectric.getForegroundThreadScheduler();
scheduler.pause();
countUp.start();
scheduler.advanceBy(CountUp.DEFAULT_TICK_DURATION_MS * 4);
assertThat(counter, is(equalTo(5)));
assertThat(completed, is(false));
scheduler.advanceBy(CountUp.DEFAULT_TICK_DURATION_MS * 6);
assertThat(counter, is(equalTo(10)));
assertThat(completed, is(true));
}
示例7: pause
import org.robolectric.util.Scheduler; //导入依赖的package包/类
@Test
public void pause() {
final CountUp countUp = new CountUp(bus);
assertThat(countUp.isRunning(), is(false));
final Scheduler scheduler = Robolectric.getForegroundThreadScheduler();
scheduler.pause();
countUp.start();
scheduler.advanceBy(CountUp.DEFAULT_TICK_DURATION_MS * 4);
assertThat(counter, is(equalTo(5)));
assertThat(completed, is(false));
countUp.pause();
assertThat(countUp.isRunning(), is(true));
scheduler.advanceBy(CountUp.DEFAULT_TICK_DURATION_MS * 6);
assertThat(counter, is(equalTo(5)));
assertThat(completed, is(false));
countUp.resume();
scheduler.advanceBy(CountUp.DEFAULT_TICK_DURATION_MS * 6);
assertThat(counter, is(equalTo(10)));
assertThat(completed, is(true));
}
示例8: basicCountUp
import org.robolectric.util.Scheduler; //导入依赖的package包/类
@Test
public void basicCountUp() {
assertThat(timer.isRunning(), is(false));
final Scheduler scheduler = Robolectric.getForegroundThreadScheduler();
scheduler.pause();
timer.start();
scheduler.advanceBy(Timer.DEFAULT_TICK_DURATION_MS * 4);
assertThat(counter, is(equalTo(5)));
assertThat(completed, is(false));
scheduler.advanceBy(Timer.DEFAULT_TICK_DURATION_MS * 6);
assertThat(counter, is(equalTo(10)));
assertThat(completed, is(true));
}
示例9: pause
import org.robolectric.util.Scheduler; //导入依赖的package包/类
@Test
public void pause() {
assertThat(timer.isRunning(), is(false));
final Scheduler scheduler = Robolectric.getForegroundThreadScheduler();
scheduler.pause();
timer.start();
scheduler.advanceBy(Timer.DEFAULT_TICK_DURATION_MS * 4);
assertThat(counter, is(equalTo(5)));
assertThat(completed, is(false));
timer.pause();
assertThat(timer.isRunning(), is(true));
scheduler.advanceBy(Timer.DEFAULT_TICK_DURATION_MS * 6);
assertThat(counter, is(equalTo(5)));
assertThat(completed, is(false));
timer.resume();
scheduler.advanceBy(Timer.DEFAULT_TICK_DURATION_MS * 6);
assertThat(counter, is(equalTo(10)));
assertThat(completed, is(true));
}
示例10: setTickDuration
import org.robolectric.util.Scheduler; //导入依赖的package包/类
@Test
public void setTickDuration() {
assertThat(timer.isRunning(), is(false));
final Scheduler scheduler = Robolectric.getForegroundThreadScheduler();
scheduler.pause();
timer.setTickDurationMs(200L);
timer.start();
scheduler.advanceBy(200L * 4);
assertThat(counter, is(equalTo(5)));
assertThat(completed, is(false));
scheduler.advanceBy(400L * 6);
assertThat(counter, is(equalTo(10)));
assertThat(completed, is(true));
}
示例11: setNumberOfTicks
import org.robolectric.util.Scheduler; //导入依赖的package包/类
@Test
public void setNumberOfTicks() {
assertThat(timer.isRunning(), is(false));
final Scheduler scheduler = Robolectric.getForegroundThreadScheduler();
scheduler.pause();
timer.setNumberOfTicks(12);
timer.start();
scheduler.advanceBy(Timer.DEFAULT_TICK_DURATION_MS * 4);
assertThat(counter, is(equalTo(5)));
assertThat(completed, is(false));
scheduler.advanceBy(Timer.DEFAULT_TICK_DURATION_MS * 5);
assertThat(counter, is(equalTo(10)));
assertThat(completed, is(false));
scheduler.advanceBy(Timer.DEFAULT_TICK_DURATION_MS * 3);
assertThat(counter, is(equalTo(12)));
assertThat(completed, is(true));
}
示例12: assertAnimateLayouts
import org.robolectric.util.Scheduler; //导入依赖的package包/类
/**
* Generic method for asserting view animation method functionality
*
* @param view The animated view
* @param trigger A {@link Runnable} that triggers the animation
*/
protected void assertAnimateLayouts(View view, Runnable trigger) {
// The foreground scheduler needs to be paused so that the
// temporary visibility of the animated View can be verified.
Scheduler foregroundScheduler = ShadowApplication.getInstance()
.getForegroundThreadScheduler();
boolean wasPaused = foregroundScheduler.isPaused();
if (!wasPaused) {
foregroundScheduler.pause();
}
assertThat(view).isGone();
trigger.run();
assertThat(view).isVisible();
Animation animation = view.getAnimation();
assertNotNull(animation);
assertThat(animation.getStartTime())
.isLessThanOrEqualTo(AnimationUtils.currentAnimationTimeMillis());
assertThat(animation).hasStartOffset(0);
foregroundScheduler.unPause();
assertThat(view).isGone();
if (wasPaused) {
foregroundScheduler.pause();
}
}
示例13: idleTasks
import org.robolectric.util.Scheduler; //导入依赖的package包/类
@Test
public void idleTasks() throws Exception {
final AtomicBoolean taskWasRun = new AtomicBoolean(false);
final Runnable task = new Runnable() {
@Override
public void run() {
taskWasRun.set(true);
}
};
animatorContext.runWhenIdle(task);
assertThat(taskWasRun.get(), is(true));
taskWasRun.set(false);
final Scheduler scheduler = Robolectric.getForegroundThreadScheduler();
animatorContext.beginAnimation("Test animation");
animatorContext.runWhenIdle(task);
assertThat(taskWasRun.get(), is(false));
// Otherwise the animator context's Handler will
// execute anything sent to it immediately.
scheduler.pause();
animatorContext.endAnimation("Test animation");
assertThat(taskWasRun.get(), is(false));
animatorContext.beginAnimation("Test animation");
assertThat(taskWasRun.get(), is(false));
animatorContext.endAnimation("Test animation");
scheduler.advanceToLastPostedRunnable();
assertThat(taskWasRun.get(), is(true));
}
示例14: schedule
import org.robolectric.util.Scheduler; //导入依赖的package包/类
@Test
public void schedule() {
final Scheduler scheduler = Robolectric.getForegroundThreadScheduler();
scheduler.pause();
powerUpTimer.schedulePowerUp(PowerUp.SLOW_DOWN_TIME,
PowerUpTimer.STANDARD_NUMBER_TICKS);
assertThat(powerUpTimer.isPending(PowerUp.SLOW_DOWN_TIME), is(true));
scheduler.advanceBy(PowerUpTimer.TICK_DURATION_MS * PowerUpTimer.STANDARD_NUMBER_TICKS + 100L);
assertThat(events.size(), is(equalTo(2)));
assertThat(events, hasItem(new PowerUpTimer.PowerUpScheduled(PowerUp.SLOW_DOWN_TIME)));
assertThat(events, hasItem(new PowerUpTimer.PowerUpExpired(PowerUp.SLOW_DOWN_TIME)));
assertThat(powerUpTimer.isPending(PowerUp.SLOW_DOWN_TIME), is(false));
}
示例15: stop
import org.robolectric.util.Scheduler; //导入依赖的package包/类
@Test
public void stop() {
final Scheduler scheduler = Robolectric.getForegroundThreadScheduler();
scheduler.pause();
powerUpTimer.schedulePowerUp(PowerUp.SLOW_DOWN_TIME,
PowerUpTimer.STANDARD_NUMBER_TICKS);
assertThat(powerUpTimer.isPending(PowerUp.SLOW_DOWN_TIME), is(true));
powerUpTimer.stop();
scheduler.advanceBy(PowerUpTimer.TICK_DURATION_MS * PowerUpTimer.STANDARD_NUMBER_TICKS + 100L);
assertThat(events.size(), is(equalTo(1)));
assertThat(powerUpTimer.isPending(PowerUp.SLOW_DOWN_TIME), is(false));
}