当前位置: 首页>>代码示例>>Java>>正文


Java ShadowLooper.pauseMainLooper方法代码示例

本文整理汇总了Java中org.robolectric.shadows.ShadowLooper.pauseMainLooper方法的典型用法代码示例。如果您正苦于以下问题:Java ShadowLooper.pauseMainLooper方法的具体用法?Java ShadowLooper.pauseMainLooper怎么用?Java ShadowLooper.pauseMainLooper使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.robolectric.shadows.ShadowLooper的用法示例。


在下文中一共展示了ShadowLooper.pauseMainLooper方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onUnsubscribePostsOffMainThread

import org.robolectric.shadows.ShadowLooper; //导入方法依赖的package包/类
@Test public void onUnsubscribePostsOffMainThread() throws InterruptedException {
  ShadowLooper.pauseMainLooper();

  final CountDownLatch latch = new CountDownLatch(1);
  final AtomicBoolean called = new AtomicBoolean();
  new Thread(new Runnable() {
    @Override public void run() {
      new MainThreadDisposable() {
        @Override protected void onDispose() {
          called.set(true);
        }
      }.dispose();
      latch.countDown();
    }
  }).start();

  assertTrue(latch.await(1, SECONDS));
  assertFalse(called.get()); // Callback has not yet run.

  ShadowLooper.runMainLooperOneTask();
  assertTrue(called.get());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:MainThreadDisposableTest.java

示例2: uiShouldNotCallActionUntilMainThreadIsPaused

import org.robolectric.shadows.ShadowLooper; //导入方法依赖的package包/类
@Test
public void uiShouldNotCallActionUntilMainThreadIsPaused() throws Exception {
    // WHEN have UI action
    Consumer<String> uiAction = mock(Consumer.class);

    // AND produce binder func
    Function<Observable<String>, Disposable> binderFunc = RxUi.ui(uiAction);

    // AND main thread is paused
    ShadowLooper.pauseMainLooper();

    // AND bind Observable via binder func
    binderFunc.apply(Observable.just("a", "b", "c"));

    // THEN action should not be called until main thread is paused
    verifyZeroInteractions(uiAction);
}
 
开发者ID:artem-zinnatullin,项目名称:RxUi,代码行数:18,代码来源:RxUiTest.java

示例3: uiShouldPreventCallsToActionIfUnsubscribedBeforeExecution

import org.robolectric.shadows.ShadowLooper; //导入方法依赖的package包/类
@Test
public void uiShouldPreventCallsToActionIfUnsubscribedBeforeExecution() throws Exception {
    // WHEN have UI action
    Consumer<String> uiAction = mock(Consumer.class);

    // AND produce binder func
    Function<Observable<String>, Disposable> binderFunc = RxUi.ui(uiAction);

    // AND pause Main Thread
    ShadowLooper.pauseMainLooper();

    // AND bind Observable via binder func
    Disposable disposable = binderFunc.apply(Observable.just("a", "b", "c"));

    // AND dispose Disposable
    disposable.dispose();

    // AND resume Main Thread
    ShadowLooper.runUiThreadTasksIncludingDelayedTasks();

    // THEN no calls to uiAction are expected
    verifyZeroInteractions(uiAction);
}
 
开发者ID:artem-zinnatullin,项目名称:RxUi,代码行数:24,代码来源:RxUiTest.java

示例4: onUnsubscribeRunsSyncOnMainThread

import org.robolectric.shadows.ShadowLooper; //导入方法依赖的package包/类
@Test public void onUnsubscribeRunsSyncOnMainThread() {
  ShadowLooper.pauseMainLooper();

  final AtomicBoolean called = new AtomicBoolean();
  new MainThreadDisposable() {
    @Override protected void onDispose() {
      called.set(true);
    }
  }.dispose();

  assertTrue(called.get());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:13,代码来源:MainThreadDisposableTest.java

示例5: testSimpleExecute

import org.robolectric.shadows.ShadowLooper; //导入方法依赖的package包/类
@Test
public void testSimpleExecute() {
  ShadowLooper.pauseMainLooper();
  mExecutorService.execute(mIncrementCounterRunnable);
  Assert.assertEquals(0, mCounter.get());
  ShadowLooper.unPauseMainLooper();
  Assert.assertEquals(1, mCounter.get());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:9,代码来源:HandlerExecutorServiceImplTest.java

示例6: testQueueSignalOnMainLooper

import org.robolectric.shadows.ShadowLooper; //导入方法依赖的package包/类
@Test
public void testQueueSignalOnMainLooper() {
    Looper looper = ShadowLooper.getMainLooper();
    SignalQueue queue = new SignalQueueImpl(looper);
    Assert.assertEquals(0, queue.getCurrentQueueSize());

    ShadowLooper.pauseMainLooper();
    queue.queueSignal(new LocalEvent());
    queue.queueSignal(new LocalEvent());
    queue.queueSignal(new DeviceEvent());
    Assert.assertEquals(3, queue.getCurrentQueueSize());

    ShadowLooper.unPauseMainLooper();
    Assert.assertEquals(0, queue.getCurrentQueueSize());
}
 
开发者ID:mocircle,项目名称:circleflow-android,代码行数:16,代码来源:SignalQueueTest.java

示例7: setUp

import org.robolectric.shadows.ShadowLooper; //导入方法依赖的package包/类
@Before
public void setUp() {
    TestApplication.applicationGraph.inject(this);
    controller = Robolectric.buildActivity(TestListActivity.class);
    activity = controller.create().postCreate(null).start().resume().get();
    // inflate menu, see https://github.com/robolectric/robolectric/issues/1326
    ShadowLooper.pauseMainLooper();
    controller.visible();
    ShadowApplication.getInstance().getForegroundThreadScheduler().advanceToLastPostedRunnable();
}
 
开发者ID:hidroh,项目名称:materialistic,代码行数:11,代码来源:BaseListActivityLandTest.java

示例8: setUp

import org.robolectric.shadows.ShadowLooper; //导入方法依赖的package包/类
@Before
public void setUp() {
  RxAndroidPlugins.getInstance().reset();
  ShadowLooper.pauseMainLooper();
}
 
开发者ID:kickstarter,项目名称:android-oss,代码行数:6,代码来源:ObserveForUITransformerTest.java

示例9: testOptionExternal

import org.robolectric.shadows.ShadowLooper; //导入方法依赖的package包/类
@SuppressLint("NewApi")
@Test
public void testOptionExternal() {
    RobolectricPackageManager packageManager = (RobolectricPackageManager)
            RuntimeEnvironment.application.getPackageManager();
    packageManager.addResolveInfoForIntent(
            new Intent(Intent.ACTION_VIEW,
                    Uri.parse("http://example.com")),
            ShadowResolveInfo.newResolveInfo("label", "com.android.chrome", "DefaultActivity"));
    packageManager.addResolveInfoForIntent(
            new Intent(Intent.ACTION_VIEW,
                    Uri.parse(String.format(HackerNewsClient.WEB_ITEM_PATH, "1"))),
            ShadowResolveInfo.newResolveInfo("label", "com.android.chrome", "DefaultActivity"));
    Intent intent = new Intent();
    intent.putExtra(ItemActivity.EXTRA_ITEM, new TestItem() {
        @NonNull
        @Override
        public String getType() {
            return STORY_TYPE;
        }

        @Override
        public String getUrl() {
            return "http://example.com";
        }

        @Override
        public boolean isStoryType() {
            return true;
        }

        @Override
        public String getId() {
            return "1";
        }
    });
    controller.withIntent(intent).create().start().resume();

    // inflate menu, see https://github.com/robolectric/robolectric/issues/1326
    ShadowLooper.pauseMainLooper();
    controller.visible();
    ShadowApplication.getInstance().getForegroundThreadScheduler().advanceToLastPostedRunnable();

    // open article
    shadowOf(activity).clickMenuItem(R.id.menu_external);
    shadowOf(ShadowPopupMenu.getLatestPopupMenu())
            .getOnMenuItemClickListener()
            .onMenuItemClick(new RoboMenuItem(R.id.menu_article));
    ShadowApplication.getInstance().getForegroundThreadScheduler().advanceToLastPostedRunnable();
    assertThat(shadowOf(activity).getNextStartedActivity()).hasAction(Intent.ACTION_VIEW);

    // open item
    shadowOf(activity).clickMenuItem(R.id.menu_external);
    shadowOf(ShadowPopupMenu.getLatestPopupMenu())
            .getOnMenuItemClickListener()
            .onMenuItemClick(new RoboMenuItem(R.id.menu_comments));
    ShadowApplication.getInstance().getForegroundThreadScheduler().advanceToLastPostedRunnable();
    assertThat(shadowOf(activity).getNextStartedActivity()).hasAction(Intent.ACTION_VIEW);
}
 
开发者ID:hidroh,项目名称:materialistic,代码行数:60,代码来源:ItemActivityTest.java

示例10: testShare

import org.robolectric.shadows.ShadowLooper; //导入方法依赖的package包/类
@SuppressLint("NewApi")
@Test
public void testShare() {
    TestApplication.addResolver(new Intent(Intent.ACTION_SEND));
    Intent intent = new Intent();
    intent.putExtra(ItemActivity.EXTRA_ITEM, new TestItem() {
        @NonNull
        @Override
        public String getType() {
            return STORY_TYPE;
        }

        @Override
        public String getUrl() {
            return "http://example.com";
        }

        @Override
        public boolean isStoryType() {
            return true;
        }

        @Override
        public String getId() {
            return "1";
        }
    });
    controller.withIntent(intent).create().start().resume();

    // inflate menu, see https://github.com/robolectric/robolectric/issues/1326
    ShadowLooper.pauseMainLooper();
    controller.visible();
    ShadowApplication.getInstance().getForegroundThreadScheduler().advanceToLastPostedRunnable();

    // share article
    shadowOf(activity).clickMenuItem(R.id.menu_share);
    shadowOf(ShadowPopupMenu.getLatestPopupMenu())
            .getOnMenuItemClickListener()
            .onMenuItemClick(new RoboMenuItem(R.id.menu_article));
    ShadowApplication.getInstance().getForegroundThreadScheduler().advanceToLastPostedRunnable();
    Intent actual = shadowOf(activity).getNextStartedActivity();
    assertThat(actual)
            .hasAction(Intent.ACTION_SEND);

    // share item
    shadowOf(activity).clickMenuItem(R.id.menu_share);
    shadowOf(ShadowPopupMenu.getLatestPopupMenu())
            .getOnMenuItemClickListener()
            .onMenuItemClick(new RoboMenuItem(R.id.menu_comments));
    ShadowApplication.getInstance().getForegroundThreadScheduler().advanceToLastPostedRunnable();
    actual = shadowOf(activity).getNextStartedActivity();
    assertThat(actual)
            .hasAction(Intent.ACTION_SEND);
}
 
开发者ID:hidroh,项目名称:materialistic,代码行数:55,代码来源:ItemActivityTest.java

示例11: testScrollToTop

import org.robolectric.shadows.ShadowLooper; //导入方法依赖的package包/类
@Config(shadows = ShadowRecyclerView.class)
@Test
public void testScrollToTop() {
    Intent intent = new Intent();
    intent.putExtra(ItemActivity.EXTRA_ITEM, new TestItem() {
        @NonNull
        @Override
        public String getType() {
            return STORY_TYPE;
        }

        @Override
        public String getId() {
            return "1";
        }

        @Override
        public boolean isStoryType() {
            return true;
        }

        @Override
        public int getKidCount() {
            return 10;
        }

        @Override
        public String getUrl() {
            return "http://example.com";
        }
    });
    controller.withIntent(intent).create().start().resume();
    // see https://github.com/robolectric/robolectric/issues/1326
    ShadowLooper.pauseMainLooper();
    controller.visible();
    ShadowApplication.getInstance().getForegroundThreadScheduler().advanceToLastPostedRunnable();
    RecyclerView recyclerView = (RecyclerView) activity.findViewById(R.id.recycler_view);
    recyclerView.smoothScrollToPosition(1);
    assertThat(customShadowOf(recyclerView).getScrollPosition()).isEqualTo(1);
    TabLayout tabLayout = (TabLayout) activity.findViewById(R.id.tab_layout);
    assertThat(tabLayout.getTabCount()).isEqualTo(2);
    tabLayout.getTabAt(1).select();
    tabLayout.getTabAt(0).select();
    tabLayout.getTabAt(0).select();
    assertThat(customShadowOf(recyclerView).getScrollPosition()).isEqualTo(0);
}
 
开发者ID:hidroh,项目名称:materialistic,代码行数:47,代码来源:ItemActivityTest.java

示例12: pauseMainLooper

import org.robolectric.shadows.ShadowLooper; //导入方法依赖的package包/类
public static void pauseMainLooper() {
  ShadowLooper.pauseMainLooper();
}
 
开发者ID:qx,项目名称:FullRobolectricTestSample,代码行数:4,代码来源:Robolectric.java


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