本文整理汇总了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());
}
示例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);
}
示例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);
}
示例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());
}
示例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());
}
示例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());
}
示例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();
}
示例8: setUp
import org.robolectric.shadows.ShadowLooper; //导入方法依赖的package包/类
@Before
public void setUp() {
RxAndroidPlugins.getInstance().reset();
ShadowLooper.pauseMainLooper();
}
示例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);
}
示例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);
}
示例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);
}
示例12: pauseMainLooper
import org.robolectric.shadows.ShadowLooper; //导入方法依赖的package包/类
public static void pauseMainLooper() {
ShadowLooper.pauseMainLooper();
}