android.support.test.annotation.UiThreadTest Java Examples
The following examples show how to use
android.support.test.annotation.UiThreadTest.
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: BottomBarTest.java From BottomBar with Apache License 2.0 | 6 votes |
@Test @UiThreadTest public void setInActiveAlpha_UpdatesAlpha() { BottomBarTab inActiveTab = bottomBar.getTabAtPosition(1); assertNotEquals(bottomBar.getCurrentTab(), inActiveTab); float previousAlpha = inActiveTab.getInActiveAlpha(); float testAlpha = 0.1f; assertNotEquals(testAlpha, previousAlpha); assertNotEquals(testAlpha, inActiveTab.getIconView().getAlpha()); assertNotEquals(testAlpha, inActiveTab.getTitleView().getAlpha()); bottomBar.setInActiveTabAlpha(testAlpha); assertEquals(testAlpha, inActiveTab.getInActiveAlpha(), 0); assertEquals(testAlpha, inActiveTab.getIconView().getAlpha(), 0); assertEquals(testAlpha, inActiveTab.getTitleView().getAlpha(), 0); }
Example #2
Source File: RxTimerSupportTest.java From Tangram-Android with MIT License | 6 votes |
@Test @SmallTest @UiThreadTest public void testTimerExecution() { assertEquals(mTimerSupport.getStatus(), TimerStatus.Waiting); mTimerSupport.register(1, new OnTickListener() { long start = System.currentTimeMillis(); @Override public void onTick() { assertEquals(Looper.myLooper(), Looper.getMainLooper()); assertEquals(mTimerSupport.getStatus(), TimerStatus.Running); long end = System.currentTimeMillis(); long time = (end - start); Log.d("RxTimerSupportTest", "testTimerExecution " + time); assertTrue(Math.abs(time - 1 * 1000) < 50); start = end; } }); }
Example #3
Source File: RxTimerSupportTest.java From Tangram-Android with MIT License | 6 votes |
@Test @SmallTest @UiThreadTest public void testTimerIntermediateArg() { assertEquals(mTimerSupport.getStatus(), TimerStatus.Waiting); mTimerSupport.register(1, new OnTickListener() { long start = System.currentTimeMillis(); @Override public void onTick() { assertEquals(Looper.myLooper(), Looper.getMainLooper()); assertEquals(mTimerSupport.getStatus(), TimerStatus.Running); long end = System.currentTimeMillis(); long time = (end - start); Log.d("RxTimerSupportTest", "testTimerIntermediateArg " + time); assertTrue(Math.abs(time) < 50 || Math.abs(time - 1 * 1000) < 50); start = end; } }, true); }
Example #4
Source File: RainbowHatInstrumentationTest.java From contrib-drivers with Apache License 2.0 | 6 votes |
/** * Verify that the buttons are not null. */ @Test @UiThreadTest public void testOpenButton() throws IOException { getInstrumentation().runOnMainSync(new Runnable() { @Override public void run() { try { Button buttonA = RainbowHat.openButtonA(); Button buttonB = RainbowHat.openButtonB(); Button buttonC = RainbowHat.openButtonC(); Assert.assertNotNull(buttonA); Assert.assertNotNull(buttonB); Assert.assertNotNull(buttonC); buttonA.close(); buttonB.close(); buttonC.close(); } catch (IOException e) { throw new RuntimeException(e); } } }); }
Example #5
Source File: FragmentNavigatorTest.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
@UiThreadTest @Test public void testSingleTopInitial() { FragmentNavigator fragmentNavigator = new FragmentNavigator(mEmptyActivity, mFragmentManager, R.id.container); FragmentNavigator.Destination destination = fragmentNavigator.createDestination(); destination.setFragmentClass(EmptyFragment.class); fragmentNavigator.navigate(destination, null, null); mFragmentManager.executePendingTransactions(); Fragment fragment = mFragmentManager.findFragmentById(R.id.container); assertThat("Fragment should be added", fragment, is(notNullValue())); fragmentNavigator.navigate(destination, null, new NavOptions.Builder().setLaunchSingleTop(true).build()); mFragmentManager.executePendingTransactions(); Fragment replacementFragment = mFragmentManager.findFragmentById(R.id.container); assertThat("Replacement Fragment should be added", replacementFragment, is(notNullValue())); assertThat("Replacement Fragment should be the correct type", replacementFragment, is(CoreMatchers.<Fragment>instanceOf(EmptyFragment.class))); assertThat("Replacement should be a new instance", replacementFragment, is(not(equalTo(fragment)))); assertThat("Old instance should be destroyed", fragment.getLifecycle().getCurrentState(), is(equalTo(Lifecycle.State.DESTROYED))); }
Example #6
Source File: RxTimerSupportTest.java From Tangram-Android with MIT License | 6 votes |
@Test @SmallTest @UiThreadTest public void testIntervalLargerThan1() { assertEquals(mTimerSupport.getStatus(), TimerStatus.Waiting); mTimerSupport.register(3, new OnTickListener() { long start = System.currentTimeMillis(); @Override public void onTick() { assertEquals(Looper.myLooper(), Looper.getMainLooper()); assertEquals(mTimerSupport.getStatus(), TimerStatus.Running); long end = System.currentTimeMillis(); long time = (end - start); Log.d("RxTimerSupportTest", "3 testTimerExecution " + time); assertTrue(Math.abs(time - 3 * 1000) < 50); start = end; } }); }
Example #7
Source File: RxTimerSupportTest.java From Tangram-Android with MIT License | 6 votes |
@Test @SmallTest @UiThreadTest public void testResume() { assertEquals(mTimerSupport.getStatus(), TimerStatus.Waiting); mTimerSupport.register(1, new OnTickListener() { @Override public void onTick() { assertEquals(Looper.myLooper(), Looper.getMainLooper()); assertEquals(mTimerSupport.getStatus(), TimerStatus.Running); Log.d("RxTimerSupportTest", "testResume"); } }); mTimerSupport.pause(); mTimerSupport.restart(); }
Example #8
Source File: RxTimerSupportTest.java From Tangram-Android with MIT License | 6 votes |
@Test @SmallTest @UiThreadTest public void testPause() { assertEquals(mTimerSupport.getStatus(), TimerStatus.Waiting); mTimerSupport.register(1, new OnTickListener() { long start = System.currentTimeMillis(); @Override public void onTick() { //should not here assertTrue(false); } }); mTimerSupport.pause(); }
Example #9
Source File: RxTimerSupportTest.java From Tangram-Android with MIT License | 6 votes |
@Test @SmallTest @UiThreadTest public void testStop() { assertEquals(mTimerSupport.getStatus(), TimerStatus.Waiting); mTimerSupport.register(1, new OnTickListener() { @Override public void onTick() { //should not here assertTrue(false); } }); mTimerSupport.register(3, new OnTickListener() { @Override public void onTick() { //should not here assertTrue(false); } }); mTimerSupport.clear(); }
Example #10
Source File: RxTimerSupportTest.java From Tangram-Android with MIT License | 6 votes |
@Test @SmallTest @UiThreadTest public void testObservableApi() { mTimerSupport.getTickObservable(2, false).subscribe(new Consumer<Long>() { long start = System.currentTimeMillis(); @Override public void accept(Long aLong) throws Exception { long end = System.currentTimeMillis(); long time = (end - start); Log.d("RxTimerSupportTest", "testObservableApi " + time); assertTrue(Math.abs(time - 2 * 1000) < 50); start = end; } }); }
Example #11
Source File: RxExposureSupportTest.java From Tangram-Android with MIT License | 6 votes |
@Test @SmallTest @UiThreadTest public void testOneCellExposure() { Consumer<ClickExposureCellOp> consumer1 = new Consumer<ClickExposureCellOp>() { @Override public void accept(ClickExposureCellOp clickEvent) throws Exception { assertEquals(clickEvent.getArg1(), mView1); assertEquals(clickEvent.getArg2(), mBaseCell1); assertEquals(clickEvent.getArg3().intValue(), 10); Log.d("RxExposureSupportTest", "testOneCellExposure test One cell mEventType " + clickEvent.getArg3()); } }; //mExposureSupport.setConsumer(consumer1); mBaseCell1.exposure(mView1); }
Example #12
Source File: VoiceHatPeripheralInstrumentationTest.java From contrib-drivers with Apache License 2.0 | 6 votes |
/** * Verify that the button is null if not passed as a parameter. */ @Test @UiThreadTest public void testButtonNull() throws IOException { InstrumentationTestUtils.assertRaspberryPiOnly(); getInstrumentation().runOnMainSync(new Runnable() { @Override public void run() { try { Button button = VoiceHat.openButton(); Assert.assertNotNull(button); button.close(); } catch (IOException e) { throw new RuntimeException(e); } } }); }
Example #13
Source File: RxClickSupportTest.java From Tangram-Android with MIT License | 6 votes |
@Test @SmallTest @UiThreadTest public void testOneCellClicks() { Consumer<ClickExposureCellOp> consumer1 = new Consumer<ClickExposureCellOp>() { @Override public void accept(ClickExposureCellOp clickEvent) throws Exception { assertEquals(clickEvent.getArg1(), mView1); assertEquals(clickEvent.getArg2(), mBaseCell1); assertEquals(clickEvent.getArg3().intValue(), 10); Log.d("RxClickSupportTest", "testOneCellClicks test One cell mEventType " + clickEvent.getArg3()); } }; //mSimpleClickSupport.setConsumer(consumer1); mBaseCell1.click(mView1); mView1.performClick(); }
Example #14
Source File: RxClickSupportTest.java From Tangram-Android with MIT License | 6 votes |
@Test @SmallTest @UiThreadTest public void testCellClickDispose() { Consumer<ClickExposureCellOp> consumer = new Consumer<ClickExposureCellOp>() { @Override public void accept(ClickExposureCellOp clickEvent) throws Exception { //should not execute this code assertTrue(false); } }; //mSimpleClickSupport.setConsumer(consumer); mBaseCell1.click(mView1); //mSimpleClickSupport.destroy(); mView1.performClick(); }
Example #15
Source File: RxExposureSupportTest.java From Tangram-Android with MIT License | 6 votes |
@Test @SmallTest @UiThreadTest public void testOneConsumerSubscribeTwoCellExposure() { Consumer<ClickExposureCellOp> consumer = new Consumer<ClickExposureCellOp>() { @Override public void accept(ClickExposureCellOp clickEvent) throws Exception { assertTrue(clickEvent.getArg1() == mView1 || clickEvent.getArg1() == mView2); assertTrue(clickEvent.getArg2() == mBaseCell1 || clickEvent.getArg2() == mBaseCell2); Log.d("RxExposureSupportTest", "testOneConsumerSubscribeTwoCellExposure mEventType " + clickEvent.getArg3()); } }; //mExposureSupport.setConsumer(consumer); mBaseCell1.exposure(mView1); mBaseCell2.exposure(mView2); }
Example #16
Source File: BottomBarTest.java From BottomBar with Apache License 2.0 | 6 votes |
@Test @UiThreadTest public void whenSelectionChanges_AndHasNoListeners_onlyOneTabIsSelectedAtATime() { bottomBar.removeOnTabSelectListener(); bottomBar.removeOnTabReselectListener(); int firstTabId = com.roughike.bottombar.test.R.id.tab_favorites; int secondTabId = com.roughike.bottombar.test.R.id.tab_nearby; int thirdTabId = com.roughike.bottombar.test.R.id.tab_friends; bottomBar.selectTabWithId(secondTabId); assertOnlyHasOnlyOneSelectedTabWithId(secondTabId); bottomBar.selectTabWithId(thirdTabId); assertOnlyHasOnlyOneSelectedTabWithId(thirdTabId); bottomBar.selectTabWithId(firstTabId); assertOnlyHasOnlyOneSelectedTabWithId(firstTabId); }
Example #17
Source File: BottomBarTest.java From BottomBar with Apache License 2.0 | 6 votes |
@Test @UiThreadTest public void whenGettingCurrentTab_ReturnsCorrectOne() { int firstTabId = com.roughike.bottombar.test.R.id.tab_favorites; bottomBar.selectTabWithId(firstTabId); assertEquals(firstTabId, bottomBar.getCurrentTabId()); assertEquals(bottomBar.findPositionForTabWithId(firstTabId), bottomBar.getCurrentTabPosition()); assertEquals(bottomBar.getTabWithId(firstTabId), bottomBar.getCurrentTab()); int secondTabId = com.roughike.bottombar.test.R.id.tab_nearby; bottomBar.selectTabWithId(secondTabId); assertEquals(secondTabId, bottomBar.getCurrentTabId()); assertEquals(bottomBar.findPositionForTabWithId(secondTabId), bottomBar.getCurrentTabPosition()); assertEquals(bottomBar.getTabWithId(secondTabId), bottomBar.getCurrentTab()); int thirdTabId = com.roughike.bottombar.test.R.id.tab_friends; bottomBar.selectTabWithId(thirdTabId); assertEquals(thirdTabId, bottomBar.getCurrentTabId()); assertEquals(bottomBar.findPositionForTabWithId(thirdTabId), bottomBar.getCurrentTabPosition()); assertEquals(bottomBar.getTabWithId(thirdTabId), bottomBar.getCurrentTab()); }
Example #18
Source File: BottomBarTest.java From BottomBar with Apache License 2.0 | 6 votes |
@Test @UiThreadTest public void setActiveAlpha_UpdatesAlpha() { BottomBarTab activeTab = bottomBar.getCurrentTab(); float previousAlpha = activeTab.getActiveAlpha(); float testAlpha = 0.69f; assertNotEquals(testAlpha, previousAlpha); assertNotEquals(testAlpha, activeTab.getIconView().getAlpha()); assertNotEquals(testAlpha, activeTab.getTitleView().getAlpha()); bottomBar.setActiveTabAlpha(testAlpha); assertEquals(testAlpha, activeTab.getActiveAlpha(), 0); assertEquals(testAlpha, activeTab.getIconView().getAlpha(), 0); assertEquals(testAlpha, activeTab.getTitleView().getAlpha(), 0); }
Example #19
Source File: BottomBarTest.java From BottomBar with Apache License 2.0 | 6 votes |
@Test @UiThreadTest public void setInActiveColor_UpdatesColor() { BottomBarTab inActiveTab = bottomBar.getTabAtPosition(1); assertNotEquals(bottomBar.getCurrentTab(), inActiveTab); int previousInActiveColor = inActiveTab.getInActiveColor(); int previousIconColor = inActiveTab.getCurrentDisplayedIconColor(); int previousTitleColor = inActiveTab.getCurrentDisplayedTitleColor(); int testColor = Color.GREEN; assertNotEquals(testColor, previousInActiveColor); assertNotEquals(testColor, previousIconColor); assertNotEquals(testColor, previousTitleColor); bottomBar.setInActiveTabColor(testColor); assertEquals(testColor, inActiveTab.getInActiveColor()); assertEquals(testColor, inActiveTab.getCurrentDisplayedIconColor()); assertEquals(testColor, inActiveTab.getCurrentDisplayedTitleColor()); }
Example #20
Source File: BottomBarTest.java From BottomBar with Apache License 2.0 | 6 votes |
@Test @UiThreadTest public void whenTabIsReselected_ReselectionListenerIsFired() { int firstTabId = com.roughike.bottombar.test.R.id.tab_favorites; bottomBar.selectTabWithId(firstTabId); verify(reselectListener, times(1)).onTabReSelected(firstTabId); int secondTabId = com.roughike.bottombar.test.R.id.tab_nearby; bottomBar.selectTabWithId(secondTabId); bottomBar.selectTabWithId(secondTabId); verify(reselectListener, times(1)).onTabReSelected(secondTabId); int thirdTabId = com.roughike.bottombar.test.R.id.tab_friends; bottomBar.selectTabWithId(thirdTabId); bottomBar.selectTabWithId(thirdTabId); verify(reselectListener, times(1)).onTabReSelected(thirdTabId); }
Example #21
Source File: BottomBarTest.java From BottomBar with Apache License 2.0 | 6 votes |
@Test @UiThreadTest public void setActiveColor_UpdatesColor() { BottomBarTab activeTab = bottomBar.getCurrentTab(); int previousActiveColor = activeTab.getActiveColor(); int previousIconColor = activeTab.getCurrentDisplayedIconColor(); int previousTitleColor = activeTab.getCurrentDisplayedTitleColor(); int testColor = Color.GRAY; assertNotEquals(testColor, previousActiveColor); assertNotEquals(testColor, previousIconColor); assertNotEquals(testColor, previousTitleColor); bottomBar.setActiveTabColor(testColor); assertEquals(testColor, activeTab.getActiveColor()); assertEquals(testColor, activeTab.getCurrentDisplayedIconColor()); assertEquals(testColor, activeTab.getCurrentDisplayedTitleColor()); }
Example #22
Source File: BottomBarTest.java From BottomBar with Apache License 2.0 | 6 votes |
@Test @UiThreadTest public void setOverrideTabSelectionListener_whenNoListenerSet() { bottomBar.removeOverrideTabSelectionListener(); BottomBarTab oldTab = bottomBar.getCurrentTab(); final BottomBarTab newTab = bottomBar.getTabAtPosition(2); getInstrumentation().runOnMainSync(new Runnable() { @Override public void run() { newTab.performClick(); } }); verify(tabSelectionInterceptor, times(0)).shouldInterceptTabSelection(oldTab.getId(), newTab.getId()); assertSame(bottomBar.getCurrentTab(), newTab); }
Example #23
Source File: BottomBarTest.java From BottomBar with Apache License 2.0 | 6 votes |
@Test @UiThreadTest public void setOverrideTabSelectionListener_allowingSelection() { bottomBar.setTabSelectionInterceptor(tabSelectionInterceptor); when(tabSelectionInterceptor.shouldInterceptTabSelection(anyInt(), anyInt())).thenReturn(false); BottomBarTab oldTab = bottomBar.getCurrentTab(); final BottomBarTab newTab = bottomBar.getTabAtPosition(2); getInstrumentation().runOnMainSync(new Runnable() { @Override public void run() { newTab.performClick(); } }); verify(tabSelectionInterceptor, times(1)).shouldInterceptTabSelection(oldTab.getId(), newTab.getId()); assertSame(bottomBar.getCurrentTab(), newTab); }
Example #24
Source File: RxClickSupportTest.java From Tangram-Android with MIT License | 6 votes |
@Test @SmallTest @UiThreadTest public void testOneCellWithMultiViewClick() { Consumer<ClickExposureCellOp> consumer = new Consumer<ClickExposureCellOp>() { @Override public void accept(ClickExposureCellOp clickEvent) throws Exception { assertTrue(clickEvent.getArg1() == mView1 || clickEvent.getArg1() == mView2); assertTrue(clickEvent.getArg2() == mBaseCell1); Log.d("RxClickSupportTest", "testOneCellWithMultiViewClick mEventType " + clickEvent.getArg3()); Log.d("RxClickSupportTest", "testOneCellWithMultiViewClick view " + clickEvent.getArg1()); } }; //mSimpleClickSupport.setConsumer(consumer); mBaseCell1.click(mView1); mBaseCell1.click(mView2); mView1.performClick(); mView2.performClick(); }
Example #25
Source File: RxClickSupportTest.java From Tangram-Android with MIT License | 6 votes |
@Test @SmallTest @UiThreadTest public void testCellClickDisposeAndResubscribe() { Consumer<ClickExposureCellOp> consumer = new Consumer<ClickExposureCellOp>() { @Override public void accept(ClickExposureCellOp clickEvent) throws Exception { assertTrue(clickEvent.getArg1() == mView1); Log.d("RxClickSupportTest", "testCellClickDisposeAndResubscribe mEventType " + clickEvent.getArg3()); } }; //mSimpleClickSupport.setConsumer(consumer); mBaseCell1.click(mView1); mBaseCell1.click(mView1); mView1.performClick(); }
Example #26
Source File: RxClickSupportTest.java From Tangram-Android with MIT License | 6 votes |
@Test @SmallTest @UiThreadTest public void testOneConsumerSubscribeTwoCellClicks() { Consumer<ClickExposureCellOp> consumer = new Consumer<ClickExposureCellOp>() { @Override public void accept(ClickExposureCellOp clickEvent) throws Exception { assertTrue(clickEvent.getArg1() == mView1 || clickEvent.getArg1() == mView2); assertTrue(clickEvent.getArg2() == mBaseCell1 || clickEvent.getArg2() == mBaseCell2); Log.d("RxClickSupportTest", "testOneConsumerSubscribeTwoCellClicks mEventType " + clickEvent.getArg3()); } }; //mSimpleClickSupport.setConsumer(consumer); mBaseCell1.click(mView1); mView1.performClick(); mBaseCell2.click(mView2); mView2.performClick(); }
Example #27
Source File: BottomBarTest.java From BottomBar with Apache License 2.0 | 5 votes |
@Test @UiThreadTest public void setBadgeBackgroundColor_UpdatesColor() { BottomBarTab inActiveTab = bottomBar.getTabAtPosition(1); inActiveTab.setBadgeCount(3); int previousBadgeColor = inActiveTab.getBadgeBackgroundColor(); int testColor = Color.GREEN; assertNotEquals(testColor, previousBadgeColor); bottomBar.setBadgeBackgroundColor(testColor); assertEquals(testColor, inActiveTab.getBadgeBackgroundColor()); }
Example #28
Source File: RecyclerViewAdapterTest.java From android-mvvm with Apache License 2.0 | 5 votes |
@Test @UiThreadTest public void bindViewHolder() throws Exception { ViewGroup view = new LinearLayout(InstrumentationRegistry.getContext()); TestViewDataBinding binding = new TestViewDataBinding(view); sut.onBindViewHolder(new RecyclerViewAdapter.DataBindingViewHolder(binding), 0); assertTrue(testBinder.lastBinding == binding); assertTrue(testBinder.lastViewModel == viewModelsSource.getValue().get(0)); assertEquals(1, binding.executePendingBindingsCallCount); }
Example #29
Source File: RecyclerViewAdapterTest.java From android-mvvm with Apache License 2.0 | 5 votes |
@Test @UiThreadTest public void recycleUnbindsViewModel() throws Exception { View view = new View(InstrumentationRegistry.getContext()); TestViewDataBinding binding = new TestViewDataBinding(view); sut.onViewRecycled(new RecyclerViewAdapter.DataBindingViewHolder(binding)); assertSame(binding, testBinder.lastBinding); assertNull(testBinder.lastViewModel); }
Example #30
Source File: WebPlayerViewCacheTest.java From unity-ads-android with Apache License 2.0 | 5 votes |
@Test @UiThreadTest public void testAddWebPlayer() { final Activity activity = activityTestRule.getActivity(); String viewId = "webplayer"; WebPlayerView expectedWebPlayerView = new WebPlayerView(activity, viewId, new JSONObject(), new JSONObject()); webPlayerViewCache.addWebPlayer(viewId, expectedWebPlayerView); WebPlayerView actualWebPlayerView = webPlayerViewCache.getWebPlayer(viewId); assertEquals(expectedWebPlayerView, actualWebPlayerView); }