Search in sources :

Example 26 with UiThreadTest

use of android.support.test.annotation.UiThreadTest in project material-components-android by material-components.

the class BottomNavigationViewTest method testItemChecking.

@UiThreadTest
@Test
@SmallTest
public void testItemChecking() throws Throwable {
    final Menu menu = mBottomNavigation.getMenu();
    assertTrue(menu.getItem(0).isChecked());
    checkAndVerifyExclusiveItem(menu, R.id.destination_home);
    checkAndVerifyExclusiveItem(menu, R.id.destination_profile);
    checkAndVerifyExclusiveItem(menu, R.id.destination_people);
}
Also used : Menu(android.view.Menu) SmallTest(android.support.test.filters.SmallTest) UiThreadTest(android.support.test.annotation.UiThreadTest) Test(org.junit.Test) SmallTest(android.support.test.filters.SmallTest) UiThreadTest(android.support.test.annotation.UiThreadTest)

Example 27 with UiThreadTest

use of android.support.test.annotation.UiThreadTest in project material-components-android by material-components.

the class TabLayoutPoolingTest method testUsingTabsFromOtherInstance.

@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 = (TabLayout) 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 = (TabLayout) activity.findViewById(R.id.tabs_2);
    tabLayout2.addTab(tabLayout2.newTab());
    tabLayout2.addTab(tabLayout2.newTab());
    tabLayout2.addTab(tabLayout2.newTab());
}
Also used : Activity(android.app.Activity) TabLayoutPoolingActivity(android.support.design.testapp.TabLayoutPoolingActivity) SmallTest(android.support.test.filters.SmallTest) UiThreadTest(android.support.test.annotation.UiThreadTest) Test(org.junit.Test) SmallTest(android.support.test.filters.SmallTest) UiThreadTest(android.support.test.annotation.UiThreadTest)

Example 28 with UiThreadTest

use of android.support.test.annotation.UiThreadTest in project material-components-android by material-components.

the class TabLayoutTest method testTabWithCustomLayoutSelection2.

@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);
}
Also used : TabLayoutActions.selectTab(android.support.design.testutils.TabLayoutActions.selectTab) LayoutInflater(android.view.LayoutInflater) SmallTest(android.support.test.filters.SmallTest) UiThreadTest(android.support.test.annotation.UiThreadTest) Test(org.junit.Test) UiThreadTest(android.support.test.annotation.UiThreadTest)

Example 29 with UiThreadTest

use of android.support.test.annotation.UiThreadTest in project material-components-android by material-components.

the class TabLayoutTest method testInflateTabLayoutWithNonTabItem.

@Test
@UiThreadTest
public void testInflateTabLayoutWithNonTabItem() throws Throwable {
    try {
        final LayoutInflater inflater = LayoutInflater.from(activityTestRule.getActivity());
        inflater.inflate(R.layout.design_tabs_with_non_tabitems, null);
    } catch (Throwable throwable) {
        assertTrue(throwable instanceof InflateException || throwable instanceof IllegalArgumentException);
    }
}
Also used : LayoutInflater(android.view.LayoutInflater) InflateException(android.view.InflateException) SmallTest(android.support.test.filters.SmallTest) UiThreadTest(android.support.test.annotation.UiThreadTest) Test(org.junit.Test) UiThreadTest(android.support.test.annotation.UiThreadTest)

Example 30 with UiThreadTest

use of android.support.test.annotation.UiThreadTest in project material-components-android by material-components.

the class TabLayoutTest method testMultipleTabsWithCustomLayoutSelection2.

@Test
@UiThreadTest
public void testMultipleTabsWithCustomLayoutSelection2() {
    final TabLayout.OnTabSelectedListener mockListener = mock(TabLayout.OnTabSelectedListener.class);
    final LayoutInflater inflater = LayoutInflater.from(activityTestRule.getActivity());
    final TabLayout tabs = (TabLayout) inflater.inflate(R.layout.design_tabs, null);
    tabs.addOnTabSelectedListener(mockListener);
    final TabLayout.Tab tab1 = tabs.newTab();
    tabs.addTab(tab1);
    verify(mockListener, times(1)).onTabSelected(eq(tab1));
    verify(mockListener, times(0)).onTabUnselected(any(TabLayout.Tab.class));
    final TabLayout.Tab tab2 = tabs.newTab();
    tabs.addTab(tab2, true);
    verify(mockListener, times(1)).onTabSelected(eq(tab2));
    verify(mockListener, times(1)).onTabUnselected(eq(tab1));
    final TabLayout.Tab tab3 = tabs.newTab();
    tabs.addTab(tab3);
    verifyNoMoreInteractions(mockListener);
    tabs.getTabAt(0).setCustomView(R.layout.design_tab_item_custom);
    tabs.getTabAt(1).setCustomView(R.layout.design_tab_item_custom);
    tabs.getTabAt(2).setCustomView(R.layout.design_tab_item_custom);
    assertEquals("Second tab is selected", 1, tabs.getSelectedTabPosition());
    assertTabCustomViewSelected(tabs);
}
Also used : TabLayoutActions.selectTab(android.support.design.testutils.TabLayoutActions.selectTab) LayoutInflater(android.view.LayoutInflater) SmallTest(android.support.test.filters.SmallTest) UiThreadTest(android.support.test.annotation.UiThreadTest) Test(org.junit.Test) UiThreadTest(android.support.test.annotation.UiThreadTest)

Aggregations

UiThreadTest (android.support.test.annotation.UiThreadTest)51 Test (org.junit.Test)48 RecordingObserver (com.jakewharton.rxbinding2.RecordingObserver)15 Action1 (rx.functions.Action1)14 Activity (android.app.Activity)9 SmallTest (android.support.test.filters.SmallTest)8 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)7 Action0 (rx.functions.Action0)7 LargeTest (android.support.test.filters.LargeTest)6 LayoutInflater (android.view.LayoutInflater)6 Menu (android.view.Menu)6 AllTypes (io.realm.entities.AllTypes)6 TextInputLayoutActivity (android.support.design.testapp.TextInputLayoutActivity)5 MediumTest (android.support.test.filters.MediumTest)5 MenuItem (android.view.MenuItem)5 TabLayoutActions.selectTab (android.support.design.testutils.TabLayoutActions.selectTab)4 Bundle (android.os.Bundle)3 KeyEvent (android.view.KeyEvent)3 Before (org.junit.Before)3 ColorDrawable (android.graphics.drawable.ColorDrawable)2