Java Code Examples for org.robolectric.shadows.ShadowLooper#idleMainLooper()
The following examples show how to use
org.robolectric.shadows.ShadowLooper#idleMainLooper() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StackControllerTest.java From react-native-navigation with MIT License | 6 votes |
@Test public void setRoot_singleChild() { activity.setContentView(uut.getView()); disablePushAnimation(child1, child2, child3); assertThat(uut.isEmpty()).isTrue(); uut.push(child1, new CommandListenerAdapter()); uut.push(child2, new CommandListenerAdapter()); ShadowLooper.idleMainLooper(); assertThat(uut.getTopBar().getTitleBar().getNavigationIcon()).isNotNull(); uut.setRoot(Collections.singletonList(child3), new CommandListenerAdapter() { @Override public void onSuccess(String childId) { assertContainsOnlyId(child3.getId()); ShadowLooper.idleMainLooper(); assertThat(uut.getTopBar().getTitleBar().getNavigationIcon()).isNull(); } }); }
Example 2
Source File: StackControllerTest.java From react-native-navigation with MIT License | 6 votes |
@Test public void push_waitForRender() { disablePushAnimation(child1); uut.push(child1, new CommandListenerAdapter()); assertThat(child1.getView().getParent()).isEqualTo(uut.getView()); child2.options.animations.push.waitForRender = new Bool(true); uut.push(child2, new CommandListenerAdapter()); // Both children are attached assertThat(child1.getView().getParent()).isEqualTo(uut.getView()); assertThat(child2.getView().getParent()).isEqualTo(uut.getView()); assertThat(child2.isViewShown()).isFalse(); verify(child2, times(0)).onViewAppeared(); child2.getView().addView(new View(activity)); ShadowLooper.idleMainLooper(); verify(child2).onViewAppeared(); assertThat(child2.isViewShown()).isTrue(); animator.endPushAnimation(child2.getView()); assertThat(child1.getView().getParent()).isNull(); }
Example 3
Source File: StackPresenterTest.java From react-native-navigation with MIT License | 6 votes |
@Test public void mergeButtons_backButtonIsRemovedIfVisibleFalse() { ViewController pushedChild = spy(new SimpleViewController(activity, childRegistry, "child2", new Options())); disablePushAnimation(child, pushedChild); parent.push(child, new CommandListenerAdapter()); assertThat(topBar.getTitleBar().getNavigationIcon()).isNull(); parent.push(pushedChild, new CommandListenerAdapter()); ShadowLooper.idleMainLooper(); verify(pushedChild).onViewAppeared(); assertThat(topBar.getTitleBar().getNavigationIcon()).isInstanceOf(BackDrawable.class); Options backButtonHidden = new Options(); backButtonHidden.topBar.buttons.back.setHidden(); uut.mergeChildOptions(backButtonHidden, backButtonHidden, parent, child); ShadowLooper.idleMainLooper(); assertThat(topBar.getTitleBar().getNavigationIcon()).isNull(); }
Example 4
Source File: StackControllerTest.java From react-native-navigation with MIT License | 5 votes |
@Test public void onDependentViewChanged_TopBarIsRenderedBehindStatusBar() { uut.initialOptions.statusBar.visible = new Bool(false); disablePushAnimation(child1); uut.push(child1, new CommandListenerAdapter()); ShadowLooper.idleMainLooper(); assertThat(uut.getTopBar().getY()).isEqualTo(0); }
Example 5
Source File: StackControllerTest.java From react-native-navigation with MIT License | 5 votes |
@Test public void onDependentViewChanged_TopBarIsRenderedBellowStatusBar() { disablePushAnimation(child1); uut.push(child1, new CommandListenerAdapter()); ShadowLooper.idleMainLooper(); assertThat(topMargin(uut.getTopBar())).isEqualTo(StatusBarUtils.getStatusBarHeight(activity)); }
Example 6
Source File: StackControllerTest.java From react-native-navigation with MIT License | 5 votes |
@Test public void onAttachToParent_doesNotCrashWhenCalledAfterDestroy() { Robolectric.getForegroundThreadScheduler().pause(); StackController spy = spy(createStack()); StackLayout view = spy.getView(); spy.push(child1, new CommandListenerAdapter()); activity.setContentView(view); child1.destroy(); ShadowLooper.idleMainLooper(); verify(spy).onAttachToParent(); }
Example 7
Source File: StackControllerTest.java From react-native-navigation with MIT License | 5 votes |
@Test public void resolvedOptionsAreAppliedWhenStackIsAttachedToParentAndNotVisible() { FrameLayout parent = new FrameLayout(activity); activity.setContentView(parent); ViewController child = new SimpleViewController(activity, childRegistry, "child1", new Options()); StackController stack = createStack(Collections.singletonList(child)); stack.getView().setVisibility(View.INVISIBLE); parent.addView(stack.getView()); ShadowLooper.idleMainLooper(); verify(presenter).applyChildOptions(any(), eq(stack), eq(child)); }
Example 8
Source File: StackControllerTest.java From react-native-navigation with MIT License | 5 votes |
@Test public void setRoot_topScreenIsStartedThenTheRest() { disablePushAnimation(child1, child2, child3); child3View = spy(new SimpleViewController.SimpleView(activity)); uut.setRoot(Arrays.asList(child1, child2, child3), new CommandListenerAdapter()); ShadowLooper.idleMainLooper(); InOrder inOrder = inOrder(child3View, child2, child1); inOrder.verify(child3View).start(); inOrder.verify(child2).start(); inOrder.verify(child1).start(); }
Example 9
Source File: StackControllerTest.java From react-native-navigation with MIT License | 5 votes |
@Test public void setRoot_multipleChildren() { Robolectric.getForegroundThreadScheduler().pause(); activity.setContentView(uut.getView()); disablePushAnimation(child1, child2, child3, child4); disablePopAnimation(child4); assertThat(uut.isEmpty()).isTrue(); uut.push(child1, new CommandListenerAdapter()); uut.push(child2, new CommandListenerAdapter()); ShadowLooper.idleMainLooper(); assertThat(uut.getTopBar().getTitleBar().getNavigationIcon()).isNotNull(); uut.setRoot(Arrays.asList(child3, child4), new CommandListenerAdapter() { @Override public void onSuccess(String childId) { assertContainsOnlyId(child3.getId(), child4.getId()); assertThat(child4.isViewShown()).isTrue(); assertThat(child3.isViewShown()).isFalse(); assertThat(uut.getCurrentChild()).isEqualTo(child4); uut.pop(Options.EMPTY, new CommandListenerAdapter()); ShadowLooper.idleMainLooper(); assertThat(uut.getTopBar().getTitleBar().getNavigationIcon()).isNull(); assertThat(uut.getCurrentChild()).isEqualTo(child3); } }); }
Example 10
Source File: StackControllerTest.java From react-native-navigation with MIT License | 5 votes |
@Test public void push_backButtonIsNotAddedIfScreenContainsLeftButton() { disablePushAnimation(child1, child2); uut.push(child1, new CommandListenerAdapter()); child2.options.topBar.buttons.left = new ArrayList<>(Collections.singleton(TitleBarHelper.iconButton("someButton", "icon.png"))); uut.push(child2, new CommandListenerAdapter()); ShadowLooper.idleMainLooper(); assertThat(topBarController.getView().getTitleBar().getNavigationIcon()).isNotNull(); verify(topBarController.getView(), times(0)).setBackButton(any()); }
Example 11
Source File: ButtonPresenterTest.java From react-native-navigation with MIT License | 5 votes |
@Test public void applyOptions_appliesColorOnButtonTextView() { MenuItem menuItem = buttonController.createAndAddButtonToTitleBar(titleBar, 0); uut.applyOptions(titleBar, menuItem, buttonController::getView); ShadowLooper.idleMainLooper(); List<TextView> textualButtons = ViewUtils.findChildrenByClass( requireNonNull(ViewUtils.findChildByClass(titleBar, ActionMenuView.class)), TextView.class, child -> true ); assertThat(textualButtons.get(0).getCurrentTextColor()).isEqualTo(Color.RED); }
Example 12
Source File: WXSDKInstanceTest.java From weex-uikit with MIT License | 5 votes |
public static void setupRoot(WXSDKInstance instance){ WXDomObject domObject = new WXDomObject(); WXVContainer comp = (WXVContainer) WXComponentFactory.newInstance(instance, domObject, null); WXComponent root = WXDivTest.create(comp); comp.addChild(root); comp.createView(); instance.onCreateFinish(); ShadowLooper.idleMainLooper(); }
Example 13
Source File: WXSDKInstanceTest.java From ucar-weex-core with Apache License 2.0 | 5 votes |
public static void setupRoot(WXSDKInstance instance){ WXDomObject domObject = new WXDomObject(); WXVContainer comp = (WXVContainer) WXComponentFactory.newInstance(instance, domObject, null); WXComponent root = WXDivTest.create(comp); comp.addChild(root); comp.createView(); instance.onCreateFinish(); ShadowLooper.idleMainLooper(); }
Example 14
Source File: LayoutDiffingTest.java From litho with Apache License 2.0 | 5 votes |
@Test public void layoutDiffing_multipleSetRootsInParallelWithShouldUpdateTrueForSecondLayout_mountContentIsRemounted() { final ArrayList<LifecycleStep> operations = new ArrayList<>(); final Object firstObjectForShouldUpdate = new Object(); mLithoViewRule .setRoot( createRootComponent( mLithoViewRule.getContext(), firstObjectForShouldUpdate, operations)) .setSizePx(100, 100) .measure() .layout() .attachToWindow(); assertThat(operations).containsExactly(LifecycleStep.ON_MOUNT); operations.clear(); final Object secondObjectForShouldUpdate = new Object(); // Do two prop updates sequentially without draining the main thread queue mLithoViewRule.setRootAsync( createRootComponent(mLithoViewRule.getContext(), firstObjectForShouldUpdate, operations)); mBackgroundLayoutLooperRule.runToEndOfTasksSync(); mLithoViewRule.setRootAsync( createRootComponent(mLithoViewRule.getContext(), secondObjectForShouldUpdate, operations)); mBackgroundLayoutLooperRule.runToEndOfTasksSync(); // Now drain the main thread queue and mount the result ShadowLooper.idleMainLooper(); mLithoViewRule.layout(); // Similar to the previous test, but the object changes on the second layout instead. assertThat(operations).containsExactly(LifecycleStep.ON_UNMOUNT, LifecycleStep.ON_MOUNT); }
Example 15
Source File: NavigationModuleTest.java From react-native-navigation with MIT License | 5 votes |
@Test public void setRoot_delegatesToNavigator() throws JSONException { when(reactApplicationContext.getCurrentActivity()).thenReturn(activity); ReadableMap root = mock(ReadableMap.class); when(jsonParser.parse(root)).thenReturn(rootJson()); ViewController rootViewController = mock(ViewController.class); when(layoutFactory.create(any(LayoutNode.class))).thenReturn(rootViewController); uut.setRoot("1", root, mock(Promise.class)); ShadowLooper.idleMainLooper(); verify(navigator).setRoot(eq(rootViewController), any(), any()); }
Example 16
Source File: LayoutDiffingTest.java From litho with Apache License 2.0 | 5 votes |
@Test public void layoutDiffing_multipleSetRootsInParallelWithShouldUpdateFalse_mountContentIsNotRemounted() { final ArrayList<LifecycleStep> operations = new ArrayList<>(); final Object firstObjectForShouldUpdate = new Object(); mLithoViewRule .setRoot( createRootComponent( mLithoViewRule.getContext(), firstObjectForShouldUpdate, operations)) .setSizePx(100, 100) .measure() .layout() .attachToWindow(); assertThat(operations) .describedAs("Test setup, there should be an initial mount") .containsExactly(LifecycleStep.ON_MOUNT); operations.clear(); // Do two prop updates sequentially without draining the main thread queue mLithoViewRule.setRootAsync( createRootComponent(mLithoViewRule.getContext(), firstObjectForShouldUpdate, operations)); mBackgroundLayoutLooperRule.runToEndOfTasksSync(); mLithoViewRule.setRootAsync( createRootComponent(mLithoViewRule.getContext(), firstObjectForShouldUpdate, operations)); mBackgroundLayoutLooperRule.runToEndOfTasksSync(); // Now drain the main thread queue and mount the result ShadowLooper.idleMainLooper(); mLithoViewRule.layout(); assertThat(operations).isEmpty(); }
Example 17
Source File: MainActivityTest.java From ActivityDiary with GNU General Public License v3.0 | 5 votes |
@Test public void currentActivity() throws Exception { /* now select an activity */ DiaryActivity someAct = new DiaryActivity(1, "Test", Color.BLACK); ActivityHelper.helper.insertActivity(someAct); assertNotNull(someAct); ActivityHelper.helper.setCurrentActivity(someAct); assertEquals(ActivityHelper.helper.getCurrentActivity(), someAct); MainActivity activity = Robolectric.setupActivity(MainActivity.class); View card = activity.findViewById(R.id.card); TextView nameView = (TextView) card.findViewById(R.id.activity_name); assertNotNull("Current activity Text available", nameView); assertEquals(nameView.getText(), "Test"); FloatingActionButton fabNoteEdit = (FloatingActionButton) activity.findViewById(R.id.fab_edit_note); FloatingActionButton fabAttachPicture = (FloatingActionButton) activity.findViewById(R.id.fab_attach_picture); assertNotNull("we have two FABs", fabNoteEdit); assertNotNull("we have two FABs", fabAttachPicture); fabNoteEdit.performClick(); DialogFragment dialogFragment = (DialogFragment) activity.getSupportFragmentManager() .findFragmentByTag("NoteEditDialogFragment"); assertNotNull(dialogFragment); ShadowLooper.idleMainLooper(100, TimeUnit.MILLISECONDS); assertNull(ShadowToast.getTextOfLatestToast()); fabAttachPicture.performClick(); ShadowLooper.idleMainLooper(100, TimeUnit.MILLISECONDS); assertNull(ShadowToast.getTextOfLatestToast()); }
Example 18
Source File: StateUpdatesWithReconciliationTest.java From litho with Apache License 2.0 | 4 votes |
/** * In this scenario, we make sure that if a state update happens in the background followed by a * second state update in the background before the first can commit on the main thread, that the * final result includes both state updates. */ @Test public void testMultipleBackgroundStateUpdates() { after(); ComponentContext c = new ComponentContext(getApplicationContext()); LithoView lithoView = new LithoView(c); ComponentTree componentTree = ComponentTree.create(c).build(); lithoView.setComponentTree(componentTree); lithoView.measure( View.MeasureSpec.makeMeasureSpec(100, View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(100, View.MeasureSpec.EXACTLY)); lithoView.layout(0, 0, 100, 100); lithoView.onAttachedToWindow(); final SimpleStateUpdateEmulatorSpec.Caller stateUpdater1 = new SimpleStateUpdateEmulatorSpec.Caller(); final SimpleStateUpdateEmulatorSpec.Caller stateUpdater2 = new SimpleStateUpdateEmulatorSpec.Caller(); componentTree.setRootAsync( Row.create(c) .child( Column.create(c) .child( SimpleStateUpdateEmulator.create(c) .caller(stateUpdater1) .widthPx(100) .heightPx(100) .prefix("First: ")) .child( SimpleStateUpdateEmulator.create(c) .caller(stateUpdater2) .widthPx(100) .heightPx(100) .prefix("Second: "))) .build()); mBackgroundLayoutLooperRule.runToEndOfTasksSync(); ShadowLooper.idleMainLooper(); lithoView.layout(0, 0, 100, 100); // Do two state updates sequentially without draining the main thread queue stateUpdater1.incrementAsync(); mBackgroundLayoutLooperRule.runToEndOfTasksSync(); stateUpdater2.incrementAsync(); mBackgroundLayoutLooperRule.runToEndOfTasksSync(); // Now drain the main thread queue and mount the result ShadowLooper.idleMainLooper(); lithoView.layout(0, 0, 100, 100); ViewAssertions.assertThat(lithoView) .matches( ViewMatchNode.forType(LithoView.class) .prop( "drawables", MatchNode.list( MatchNode.forType(TextDrawable.class).prop("text", "First: 2"), MatchNode.forType(TextDrawable.class).prop("text", "Second: 2")))); }
Example 19
Source File: JobServiceTest.java From firebase-jobdispatcher-android with Apache License 2.0 | 4 votes |
private static void flush(JobService jobService) throws Exception { flushExecutorService(jobService.backgroundExecutor); ShadowLooper.idleMainLooper(); }
Example 20
Source File: MainActivityTest.java From ActivityDiary with GNU General Public License v3.0 | 3 votes |
@Test public void currentNullActivity() throws Exception { /* show absense of #60 */ MainActivity activity = Robolectric.setupActivity(MainActivity.class); View card = activity.findViewById(R.id.card); assertNotNull("Current activity card available", card); TextView nameView = (TextView) card.findViewById(R.id.activity_name); assertNotNull("Current activity Text available", nameView); /* initial creation shall not have any activity selected */ assertEquals(nameView.getText(), "<No Activity>"); assertNull(ActivityHelper.helper.getCurrentActivity()); FloatingActionButton fabNoteEdit = (FloatingActionButton) activity.findViewById(R.id.fab_edit_note); FloatingActionButton fabAttachPicture = (FloatingActionButton) activity.findViewById(R.id.fab_attach_picture); assertNotNull("we have two FABs", fabNoteEdit); assertNotNull("we have two FABs", fabAttachPicture); fabNoteEdit.performClick(); ShadowLooper.idleMainLooper(100, TimeUnit.MILLISECONDS); assertEquals(ShadowToast.getTextOfLatestToast().toString(), "To perform this action it is necessary to select an activity first"); fabAttachPicture.performClick(); ShadowLooper.idleMainLooper(100, TimeUnit.MILLISECONDS); assertEquals(ShadowToast.getTextOfLatestToast().toString(), "To perform this action it is necessary to select an activity first"); }