• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Scheduler类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.robolectric.util.Scheduler的典型用法代码示例。如果您正苦于以下问题:Java Scheduler类的具体用法?Java Scheduler怎么用?Java Scheduler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Scheduler类属于org.robolectric.util包,在下文中一共展示了Scheduler类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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));
}
 
开发者ID:hello,项目名称:anime-android-go-99,代码行数:18,代码来源:MultiAnimatorTests.java


示例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));
}
 
开发者ID:hello,项目名称:anime-android-go-99,代码行数:27,代码来源:MultiAnimatorTests.java


示例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));
}
 
开发者ID:decarbonization,项目名称:android-fonz,代码行数:19,代码来源:PowerUpTimerTests.java


示例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)));
}
 
开发者ID:decarbonization,项目名称:android-fonz,代码行数:21,代码来源:GameTests.java


示例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))));
}
 
开发者ID:decarbonization,项目名称:android-fonz,代码行数:21,代码来源:GameTests.java


示例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));
}
 
开发者ID:decarbonization,项目名称:android-fonz,代码行数:19,代码来源:CountUpTests.java


示例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));
}
 
开发者ID:decarbonization,项目名称:android-fonz,代码行数:27,代码来源:CountUpTests.java


示例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));
}
 
开发者ID:decarbonization,项目名称:android-fonz,代码行数:17,代码来源:TimerTests.java


示例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));
}
 
开发者ID:decarbonization,项目名称:android-fonz,代码行数:25,代码来源:TimerTests.java


示例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));
}
 
开发者ID:decarbonization,项目名称:android-fonz,代码行数:18,代码来源:TimerTests.java


示例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));
}
 
开发者ID:decarbonization,项目名称:android-fonz,代码行数:22,代码来源:TimerTests.java


示例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();
    }
}
 
开发者ID:edx,项目名称:edx-app-android,代码行数:30,代码来源:BaseFragmentActivityTest.java


示例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));
}
 
开发者ID:hello,项目名称:anime-android-go-99,代码行数:35,代码来源:AnimatorContextTests.java


示例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));
}
 
开发者ID:decarbonization,项目名称:android-fonz,代码行数:16,代码来源:PowerUpTimerTests.java


示例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));
}
 
开发者ID:decarbonization,项目名称:android-fonz,代码行数:15,代码来源:PowerUpTimerTests.java


示例16: pause

import org.robolectric.util.Scheduler; //导入依赖的package包/类
@Test
public void pause() {
    final Scheduler scheduler = Robolectric.getForegroundThreadScheduler();
    scheduler.pause();

    game.newGame();
    game.powerUpTimer.schedulePowerUp(PowerUp.MULTIPLY_SCORE,
                                        CountUp.NUMBER_TICKS);
    scheduler.advanceBy(CountUp.DEFAULT_TICK_DURATION_MS * 2L);

    final long beforePause = game.countUp.getTickDurationMs();
    game.pause();
    assertThat(game.isPaused(), is(true));

    scheduler.advanceBy(CountUp.DEFAULT_TICK_DURATION_MS + 10L);
    assertThat(game.countUp.getTickDurationMs(), is(equalTo(beforePause)));
    assertThat(game.powerUpTimer.isPending(PowerUp.MULTIPLY_SCORE), is(true));

    game.resume();
    assertThat(game.isPaused(), is(false));

    scheduler.advanceBy(CountUp.DEFAULT_TICK_DURATION_MS * CountUp.NUMBER_TICKS * 3);
    assertThat(game.countUp.getTickDurationMs(), is(not(equalTo(beforePause))));
    assertThat(game.powerUpTimer.isPending(PowerUp.MULTIPLY_SCORE), is(false));

    game.pause();
    assertThat(game.isPaused(), is(true));

    game.gameOver(Game.GameOver.How.GAME_LOGIC);
    assertThat(game.isPaused(), is(false));
}
 
开发者ID:decarbonization,项目名称:android-fonz,代码行数:32,代码来源:GameTests.java


示例17: startAfterPause

import org.robolectric.util.Scheduler; //导入依赖的package包/类
@Test
public void startAfterPause() {
    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));

    this.counter = 0;
    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));
}
 
开发者ID:decarbonization,项目名称:android-fonz,代码行数:33,代码来源:TimerTests.java


示例18: execAllAsyncTask

import org.robolectric.util.Scheduler; //导入依赖的package包/类
static public void execAllAsyncTask(){
    Scheduler bgTask = Robolectric.getBackgroundThreadScheduler();
    Scheduler fgTask = Robolectric.getForegroundThreadScheduler();

    while (fgTask.size()!=0 || bgTask.size()!=0){
        Robolectric.flushBackgroundThreadScheduler();
        Robolectric.flushForegroundThreadScheduler();
        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
 
开发者ID:STMicroelectronics-CentralLabs,项目名称:BlueSTSDK_Android,代码行数:15,代码来源:TestUtil.java


示例19: shadowOf

import org.robolectric.util.Scheduler; //导入依赖的package包/类
@Test public void soStaticRefsToLoopersInAppWorksAcrossTests_shouldRetainSameLooperForMainThreadBetweenResetsButGiveItAFreshScheduler() throws Exception {
  Looper mainLooper = Looper.getMainLooper();
  Scheduler scheduler = shadowOf(mainLooper).getScheduler();
  shadowOf(mainLooper).quit = true;
  assertThat(Robolectric.application.getMainLooper()).isSameAs(mainLooper);

  ShadowLooper.resetThreadLoopers();
  Robolectric.application = new Application();

  assertThat(Looper.getMainLooper()).isSameAs(mainLooper);
  assertThat(Robolectric.application.getMainLooper()).isSameAs(mainLooper);
  assertThat(shadowOf(mainLooper).getScheduler()).isNotSameAs(scheduler);
  assertThat(shadowOf(mainLooper).hasQuit()).isFalse();
}
 
开发者ID:qx,项目名称:FullRobolectricTestSample,代码行数:15,代码来源:LooperTest.java


示例20: cancelFromAnimeBeforeNextLooperCycle

import org.robolectric.util.Scheduler; //导入依赖的package包/类
@Test
public void cancelFromAnimeBeforeNextLooperCycle() {
    final Scheduler scheduler = Robolectric.getForegroundThreadScheduler();
    scheduler.pause();

    final AnimatorContext testContext = spy(new AnimatorContext("Test"));

    final MultiAnimator animator = MultiAnimator.animatorFor(fakeView, testContext);
    animator.translationY(100f);
    animator.start();

    verify(testContext).beginAnimation(any(String.class));

    Anime.cancelAll(fakeView);

    verify(testContext).endAnimation(any(String.class));

    assertThat(fakeView.getTranslationY(), is(equalTo(0f)));
}
 
开发者ID:hello,项目名称:anime-android-go-99,代码行数:20,代码来源:MultiAnimatorTests.java



注:本文中的org.robolectric.util.Scheduler类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java TreeClassChooserFactory类代码示例发布时间:2022-05-22
下一篇:
Java OFActionVendor类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap