androidx.test.annotation.UiThreadTest Java Examples
The following examples show how to use
androidx.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: ResettingStubberImplTest.java From android-test with Apache License 2.0 | 6 votes |
@UiThreadTest @Test public void setActivityResultMultipleTime() { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.android.com")); ActivityResult result = new ActivityResult(10, intent); ActivityResult duplicateResult = new ActivityResult(100, new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"))); Matcher<Intent> matcher = allOf(hasAction(equalTo(Intent.ACTION_VIEW)), hasData(hasHost(equalTo("www.android.com")))); resettingStubber.setActivityResultForIntent(matcher, result); resettingStubber.setActivityResultForIntent(matcher, duplicateResult); assertEquals( "Activity result didn't match expected value.", resettingStubber.getActivityResultForIntent(intent), duplicateResult); assertEquals( "Activity result didn't match expected value.", resettingStubber.getActivityResultForIntent(intent), duplicateResult); }
Example #2
Source File: BottomNavigationViewTest.java From material-components-android with Apache License 2.0 | 6 votes |
@UiThreadTest @Test @SmallTest @SdkSuppress(minSdkVersion = Build.VERSION_CODES.N) @TargetApi(Build.VERSION_CODES.N) public void testPointerIcon() throws Throwable { final Activity activity = activityTestRule.getActivity(); final PointerIcon expectedIcon = PointerIcon.getSystemIcon(activity, PointerIcon.TYPE_HAND); final MotionEvent event = MotionEvent.obtain(0, 0, MotionEvent.ACTION_HOVER_MOVE, 0, 0, 0); final Menu menu = bottomNavigation.getMenu(); for (int i = 0; i < menu.size(); i++) { final MenuItem item = menu.getItem(i); assertTrue(item.isEnabled()); final View itemView = activity.findViewById(item.getItemId()); assertEquals(expectedIcon, itemView.onResolvePointerIcon(event, 0)); item.setEnabled(false); assertEquals(null, itemView.onResolvePointerIcon(event, 0)); item.setEnabled(true); assertEquals(expectedIcon, itemView.onResolvePointerIcon(event, 0)); } }
Example #3
Source File: BottomNavigationViewTest.java From material-components-android with Apache License 2.0 | 6 votes |
@UiThreadTest @Test @SmallTest public void testSettingAutoItemVisibility() throws Throwable { bottomNavigation.getMenu().clear(); bottomNavigation.setLabelVisibilityMode(LabelVisibilityMode.LABEL_VISIBILITY_AUTO); bottomNavigation.inflateMenu( R.menu.bottom_navigation_view_shifting_with_invisible_button_content); assertEquals(4, bottomNavigation.getMenu().size()); final MenuItem destinationMenuItem = bottomNavigation.getMenu().findItem(R.id.destination_profile); assertFalse(destinationMenuItem.isVisible()); destinationMenuItem.setVisible(true); assertTrue(destinationMenuItem.isVisible()); }
Example #4
Source File: TabLayoutPoolingTest.java From material-components-android with Apache License 2.0 | 6 votes |
@UiThreadTest @SmallTest @Test public void testUsingTabsFromOtherInstance() { final Activity activity = activityTestRule.getActivity(); // TabLayout1 has items added via the layout, so we'll just check they're // there first final TabLayout tabLayout1 = activity.findViewById(R.id.tabs_1); assertTrue(tabLayout1.getTabCount() > 0); // Now remove all tabs. TabLayout will pool the Tab instances... tabLayout1.removeAllTabs(); // Now add some tabs to the second TabLayout and make sure that we don't crash final TabLayout tabLayout2 = activity.findViewById(R.id.tabs_2); tabLayout2.addTab(tabLayout2.newTab()); tabLayout2.addTab(tabLayout2.newTab()); tabLayout2.addTab(tabLayout2.newTab()); }
Example #5
Source File: BottomNavigationViewTest.java From material-components-android with Apache License 2.0 | 6 votes |
@UiThreadTest @Test @SmallTest public void testSettingMenuItemVisibility() throws Throwable { final MenuItem homeMenuItem = bottomNavigation.getMenu().findItem(R.id.destination_home); assertTrue(homeMenuItem.isVisible()); homeMenuItem.setVisible(false); assertFalse(homeMenuItem.isVisible()); bottomNavigation.getMenu().clear(); bottomNavigation.inflateMenu(R.menu.bottom_navigation_view_with_invisible_button_content); assertEquals(3, bottomNavigation.getMenu().size()); final MenuItem destinationMenuItem = bottomNavigation.getMenu().findItem(R.id.destination_profile); assertFalse(destinationMenuItem.isVisible()); destinationMenuItem.setVisible(true); assertTrue(destinationMenuItem.isVisible()); }
Example #6
Source File: TabLayoutTest.java From material-components-android with Apache License 2.0 | 6 votes |
@Test @UiThreadTest public void testTabWithCustomLayoutSelection1() { final TabLayout.OnTabSelectedListener mockListener = mock(TabLayout.OnTabSelectedListener.class); final LayoutInflater inflater = LayoutInflater.from(activityTestRule.getActivity()); final TabLayout tabLayout = (TabLayout) inflater.inflate(R.layout.design_tabs, null); tabLayout.addOnTabSelectedListener(mockListener); final TabLayout.Tab tab = tabLayout.newTab(); tab.setCustomView(R.layout.design_tab_item_custom); tabLayout.addTab(tab); verify(mockListener, times(1)).onTabSelected(eq(tab)); verify(mockListener, times(0)).onTabUnselected(any(TabLayout.Tab.class)); assertNotNull("Tab has custom view", tab.getCustomView()); assertEquals("First tab is selected", 0, tabLayout.getSelectedTabPosition()); assertTabCustomViewSelected(tabLayout); }
Example #7
Source File: TabLayoutTest.java From material-components-android with Apache License 2.0 | 6 votes |
@Test @UiThreadTest public void testTabWithCustomLayoutSelection2() { final TabLayout.OnTabSelectedListener mockListener = mock(TabLayout.OnTabSelectedListener.class); final LayoutInflater inflater = LayoutInflater.from(activityTestRule.getActivity()); final TabLayout tabLayout = (TabLayout) inflater.inflate(R.layout.design_tabs, null); tabLayout.addOnTabSelectedListener(mockListener); final TabLayout.Tab tab = tabLayout.newTab(); tabLayout.addTab(tab); verify(mockListener, times(1)).onTabSelected(eq(tab)); verify(mockListener, times(0)).onTabUnselected(any(TabLayout.Tab.class)); tab.setCustomView(R.layout.design_tab_item_custom); assertNotNull("Tab has custom view", tab.getCustomView()); assertEquals("First tab is selected", 0, tabLayout.getSelectedTabPosition()); assertTabCustomViewSelected(tabLayout); }
Example #8
Source File: RealmBaseAdapterTests.java From realm-android-adapters with Apache License 2.0 | 6 votes |
@Test @UiThreadTest public void testSortWithAdapter() { RealmResults<AllJavaTypes> resultList = realm.where(AllJavaTypes.class).findAll(); resultList.sort(AllJavaTypes.FIELD_STRING, Sort.DESCENDING); ListViewTestAdapter realmAdapter = new ListViewTestAdapter(context, resultList); //noinspection ConstantConditions assertEquals(resultList.first().getFieldString(), realmAdapter.getItem(0).getFieldString()); assertEquals(resultList.size(), realmAdapter.getCount()); resultList.sort(AllJavaTypes.FIELD_STRING); //noinspection ConstantConditions assertEquals(resultList.last().getFieldString(), realmAdapter.getItem(resultList.size() - 1).getFieldString()); //noinspection ConstantConditions assertEquals(resultList.get(TEST_DATA_SIZE / 2).getFieldString(), realmAdapter.getItem(TEST_DATA_SIZE / 2).getFieldString()); assertEquals(resultList.size(), realmAdapter.getCount()); }
Example #9
Source File: ViewMatchersTest.java From android-test with Apache License 2.0 | 6 votes |
@UiThreadTest @Test public void withSpinnerTextString() { Spinner spinner = new Spinner(this.context); List<String> values = Lists.newArrayList(); values.add("Hello World"); values.add("Goodbye!!"); ArrayAdapter<String> adapter = new ArrayAdapter<String>(this.context, android.R.layout.simple_spinner_item, values); spinner.setAdapter(adapter); spinner.setSelection(0); spinner.setTag("spinner"); assertTrue(withSpinnerText(is("Hello World")).matches(spinner)); assertFalse(withSpinnerText(is("Goodbye!!")).matches(spinner)); assertFalse(withSpinnerText(is("")).matches(spinner)); }
Example #10
Source File: ResettingStubberImplTest.java From android-test with Apache License 2.0 | 6 votes |
@UiThreadTest @Test public void setActivityResultFunctionMultipleTime() { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.android.com")); ActivityResult result = new ActivityResult(10, intent); ActivityResult duplicateResult = new ActivityResult(100, new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"))); Matcher<Intent> matcher = allOf(hasAction(equalTo(Intent.ACTION_VIEW)), hasData(hasHost(equalTo("www.android.com")))); resettingStubber.setActivityResultFunctionForIntent(matcher, unused -> result); resettingStubber.setActivityResultFunctionForIntent(matcher, unused -> duplicateResult); assertEquals( "Activity result didn't match expected value.", resettingStubber.getActivityResultForIntent(intent), duplicateResult); assertEquals( "Activity result didn't match expected value.", resettingStubber.getActivityResultForIntent(intent), duplicateResult); }
Example #11
Source File: TabLayoutTest.java From material-components-android with Apache License 2.0 | 6 votes |
@Test @UiThreadTest @SdkSuppress(minSdkVersion = Build.VERSION_CODES.N) @TargetApi(Build.VERSION_CODES.N) public void testPointerIcon() { final LayoutInflater inflater = LayoutInflater.from(activityTestRule.getActivity()); final TabLayout tabLayout = (TabLayout) inflater.inflate(R.layout.design_tabs_items, null); final PointerIcon expectedIcon = PointerIcon.getSystemIcon(activityTestRule.getActivity(), PointerIcon.TYPE_HAND); final int tabCount = tabLayout.getTabCount(); assertEquals(3, tabCount); final MotionEvent event = MotionEvent.obtain(0, 0, MotionEvent.ACTION_HOVER_MOVE, 0, 0, 0); for (int i = 0; i < tabCount; i++) { assertEquals(expectedIcon, tabLayout.getTabAt(i).view.onResolvePointerIcon(event, 0)); } }
Example #12
Source File: TextInputLayoutTest.java From material-components-android with Apache License 2.0 | 6 votes |
@UiThreadTest @Test public void testExtractUiHintSet() { final Activity activity = activityTestRule.getActivity(); // Set a hint on the TextInputLayout final TextInputLayout layout = activity.findViewById(R.id.textinput); layout.setHint(INPUT_TEXT); final EditText editText = activity.findViewById(R.id.textinput_edittext); // Now manually pass in a EditorInfo to the EditText and make sure it updates the // hintText to our known value final EditorInfo info = new EditorInfo(); editText.onCreateInputConnection(info); assertEquals(INPUT_TEXT, info.hintText.toString()); }
Example #13
Source File: TextInputLayoutTest.java From material-components-android with Apache License 2.0 | 6 votes |
@UiThreadTest @Test @SdkSuppress(minSdkVersion = Build.VERSION_CODES.O) public void testDispatchProvideAutofillStructure() { final Activity activity = activityTestRule.getActivity(); final TextInputLayout layout = activity.findViewById(R.id.textinput); final ViewStructureImpl structure = new ViewStructureImpl(); layout.dispatchProvideAutofillStructure(structure, 0); assertEquals(2, structure.getChildCount()); // EditText and TextView // Asserts the structure. final ViewStructureImpl childStructure = structure.getChildAt(0); assertEquals(EditText.class.getName(), childStructure.getClassName()); assertEquals("Hint to the user", childStructure.getHint().toString()); // Make sure the widget's hint was restored. assertEquals("Hint to the user", layout.getHint().toString()); final EditText editText = activity.findViewById(R.id.textinput_edittext); assertNull(editText.getHint()); }
Example #14
Source File: MainActivityTest.java From meat-grinder with MIT License | 6 votes |
@UiThreadTest @Test public void testOnProcessFinishedAndOnUpdateResult() { mActivityRule.getActivity().onUpdateResult(null); mActivityRule.getActivity().onProcessFinished(null); ArrayList<CheckInfo> list = new ArrayList<>(); TotalResult totalResult = new TotalResult(list, CH_STATE_UNCHECKED); activity.onProcessFinished(totalResult); totalResult = new TotalResult(list, CH_STATE_CHECKED_ROOT_NOT_DETECTED); activity.onProcessFinished(totalResult); totalResult = new TotalResult(list, CH_STATE_CHECKED_ERROR); activity.onProcessFinished(totalResult); totalResult = new TotalResult(list, CH_STATE_STILL_GOING); activity.onProcessFinished(totalResult); totalResult = new TotalResult(list, CH_STATE_CHECKED_ROOT_DETECTED); activity.onProcessFinished(totalResult); //noinspection WrongConstant totalResult = new TotalResult(list, Integer.MAX_VALUE); Exception exception = null; try { activity.onProcessFinished(totalResult); } catch (IllegalStateException e) { exception = e; } Assert.assertNotNull(exception); }
Example #15
Source File: RealmRecyclerAdapterTests.java From realm-android-adapters with Apache License 2.0 | 6 votes |
@Test @UiThreadTest public void updateData_replaceInvalidData() { // test for https://github.com/realm/realm-android-adapters/issues/58 final RealmConfiguration configuration = realm.getConfiguration(); RealmResults<AllJavaTypes> resultList = realm.where(AllJavaTypes.class).sort(AllJavaTypes.FIELD_STRING).findAll(); RecyclerViewTestAdapter realmAdapter = new RecyclerViewTestAdapter(context, resultList, true); realm.close(); // to make resultList invalid // check precondition assertFalse(resultList.isValid()); realm = Realm.getInstance(configuration); // create another valid RealmResults and check if updateData does not throw an exception. resultList = realm.where(AllJavaTypes.class).findAll(); realmAdapter.updateData(resultList); }
Example #16
Source File: RealmRecyclerAdapterTests.java From realm-android-adapters with Apache License 2.0 | 6 votes |
@Test @UiThreadTest public void updateData_realmResultInAdapter() { RealmResults<AllJavaTypes> resultList = realm.where(AllJavaTypes.class).findAll(); resultList.sort(AllJavaTypes.FIELD_STRING); RecyclerViewTestAdapter realmAdapter = new RecyclerViewTestAdapter(context, resultList, false); //noinspection ConstantConditions assertEquals(resultList.first().getFieldString(), realmAdapter.getData().first().getFieldString()); assertEquals(resultList.size(), realmAdapter.getData().size()); realm.beginTransaction(); AllJavaTypes allTypes = realm.createObject(AllJavaTypes.class, TEST_DATA_SIZE); allTypes.setFieldString("test data " + TEST_DATA_SIZE); realm.commitTransaction(); assertEquals(resultList.last().getFieldString(), realmAdapter.getData().last().getFieldString()); assertEquals(resultList.size(), realmAdapter.getData().size()); RealmResults<AllJavaTypes> emptyResultList = realm.where(AllJavaTypes.class).equalTo(AllJavaTypes.FIELD_STRING, "Not there").findAll(); realmAdapter.updateData(emptyResultList); assertEquals(emptyResultList.size(), realmAdapter.getData().size()); }
Example #17
Source File: TextInputLayoutTest.java From material-components-android with Apache License 2.0 | 6 votes |
@UiThreadTest @Test public void testMaintainsStartEndCompoundDrawables() throws Throwable { final Activity activity = activityTestRule.getActivity(); // Set a known set of test compound drawables on the EditText final Drawable start = new ColorDrawable(Color.RED); final Drawable top = new ColorDrawable(Color.GREEN); final Drawable end = new ColorDrawable(Color.BLUE); final Drawable bottom = new ColorDrawable(Color.BLACK); final TextInputEditText editText = new TextInputEditText(activity); TextViewCompat.setCompoundDrawablesRelative(editText, start, top, end, bottom); // Now add the EditText to a TextInputLayout TextInputLayout til = activity.findViewById(R.id.textinput_noedittext); til.addView(editText); // Finally assert that all of the drawables are untouched final Drawable[] compoundDrawables = TextViewCompat.getCompoundDrawablesRelative(editText); assertSame(start, compoundDrawables[0]); assertSame(top, compoundDrawables[1]); assertSame(end, compoundDrawables[2]); assertSame(bottom, compoundDrawables[3]); }
Example #18
Source File: RealmBaseAdapterTests.java From realm-android-adapters with Apache License 2.0 | 5 votes |
@Test @UiThreadTest public void testNullToNonNullResults() { RealmResults<AllJavaTypes> resultList = realm.where(AllJavaTypes.class).findAll(); ListViewTestAdapter realmAdapter = new ListViewTestAdapter(context, null); realmAdapter.updateData(resultList); assertEquals(TEST_DATA_SIZE, realmAdapter.getCount()); }
Example #19
Source File: ResettingStubberImplTest.java From android-test with Apache License 2.0 | 5 votes |
@UiThreadTest @Test public void reset_getActivityResultForIntent() { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.android.com")); ActivityResult result = new ActivityResult(10, intent); resettingStubber.setActivityResultForIntent(any(Intent.class), result); assertEquals(resettingStubber.getActivityResultForIntent(intent), result); resettingStubber.reset(); resettingStubber.initialize(); assertEquals(null, resettingStubber.getActivityResultForIntent(intent)); }
Example #20
Source File: TestNameDetectorTest.java From screenshot-tests-for-android with Apache License 2.0 | 5 votes |
@Test @UiThreadTest public void testTestNameIsDetected() throws Throwable { assertEquals("testTestNameIsDetected", TestNameDetector.getTestName()); assertEquals( "com.facebook.testing.screenshot.internal.TestNameDetectorTest", TestNameDetector.getTestClass()); }
Example #21
Source File: ResettingStubberImplTest.java From android-test with Apache License 2.0 | 5 votes |
@UiThreadTest @Test public void isInitialized() { assertTrue(resettingStubber.isInitialized()); resettingStubber.reset(); assertFalse(resettingStubber.isInitialized()); resettingStubber.initialize(); assertTrue(resettingStubber.isInitialized()); }
Example #22
Source File: RealmBaseAdapterTests.java From realm-android-adapters with Apache License 2.0 | 5 votes |
@Test @UiThreadTest public void adapterIsEmptyAfterClose() { RealmResults<AllJavaTypes> result = realm.where(AllJavaTypes.class).findAll(); ListViewTestAdapter realmAdapter = new ListViewTestAdapter(context, result); realm.close(); assertTrue(realm.isClosed()); realm = null; assertEquals(0, realmAdapter.getCount()); assertNull(realmAdapter.getItem(0)); }
Example #23
Source File: RealmRecyclerAdapterTests.java From realm-android-adapters with Apache License 2.0 | 5 votes |
@Test @UiThreadTest public void getItemCount_testNotValidResults() { RealmResults<AllJavaTypes> resultList = realm.where(AllJavaTypes.class).findAll(); RecyclerViewTestAdapter realmAdapter = new RecyclerViewTestAdapter(context, resultList, AUTOMATIC_UPDATE); realm.close(); assertEquals(0, realmAdapter.getItemCount()); }
Example #24
Source File: ViewMatchersTest.java From android-test with Apache License 2.0 | 5 votes |
@Test @UiThreadTest public void withInputType_ReturnsTrueIf_CorrectInput() { EditText editText = new EditText(context); editText.setInputType(InputType.TYPE_CLASS_NUMBER); assertTrue(withInputType(InputType.TYPE_CLASS_NUMBER).matches(editText)); }
Example #25
Source File: RealmRecyclerAdapterTests.java From realm-android-adapters with Apache License 2.0 | 5 votes |
@Before @UiThreadTest public void setUp() { context = InstrumentationRegistry.getInstrumentation().getContext(); RealmConfiguration realmConfig = new RealmConfiguration.Builder(context).modules(new RealmTestModule()).build(); Realm.deleteRealm(realmConfig); realm = Realm.getInstance(realmConfig); realm.beginTransaction(); for (int i = 0; i < TEST_DATA_SIZE; i++) { AllJavaTypes allTypes = realm.createObject(AllJavaTypes.class, i); allTypes.setFieldString("test data " + i); } realm.commitTransaction(); }
Example #26
Source File: RealmRecyclerAdapterTests.java From realm-android-adapters with Apache License 2.0 | 5 votes |
@Test @UiThreadTest public void clear() { RealmResults<AllJavaTypes> resultList = realm.where(AllJavaTypes.class).findAll(); RecyclerViewTestAdapter realmAdapter = new RecyclerViewTestAdapter(context, resultList, AUTOMATIC_UPDATE); realm.beginTransaction(); resultList.deleteAllFromRealm(); realm.commitTransaction(); assertEquals(0, realmAdapter.getItemCount()); assertEquals(0, resultList.size()); }
Example #27
Source File: RealmRecyclerAdapterTests.java From realm-android-adapters with Apache License 2.0 | 5 votes |
@Test @UiThreadTest public void getItemCount_testGetCount() { RealmResults<AllJavaTypes> resultList = realm.where(AllJavaTypes.class).findAll(); RecyclerViewTestAdapter realmAdapter = new RecyclerViewTestAdapter(context, resultList, AUTOMATIC_UPDATE); assertEquals(TEST_DATA_SIZE, realmAdapter.getItemCount()); }
Example #28
Source File: RealmRecyclerAdapterTests.java From realm-android-adapters with Apache License 2.0 | 5 votes |
@Test @UiThreadTest public void getItemId_testGetItemId() { RealmResults<AllJavaTypes> resultList = realm.where(AllJavaTypes.class).findAll(); RecyclerViewTestAdapter realmAdapter = new RecyclerViewTestAdapter(context, resultList, AUTOMATIC_UPDATE); for (int i = 0; i < resultList.size(); i++) { assertEquals(i, realmAdapter.getItemId(i)); } }
Example #29
Source File: ViewFinderImplTest.java From android-test with Apache License 2.0 | 5 votes |
@Test @UiThreadTest public void getView_missing() { ViewFinder finder = new ViewFinderImpl(nullValue(View.class), testViewProvider); expectedException.expect(NoMatchingViewException.class); finder.getView(); }
Example #30
Source File: ViewMatchersTest.java From android-test with Apache License 2.0 | 5 votes |
@Test @UiThreadTest public void supportsInputMethodsTest() { Button button = new Button(context); EditText editText = new EditText(context); assertFalse(supportsInputMethods().matches(button)); assertTrue(supportsInputMethods().matches(editText)); }