Search in sources :

Example 1 with UiThreadTest

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

the class TabLayoutTest method testInflateTabLayoutWithTabItems.

@Test
@UiThreadTest
public void testInflateTabLayoutWithTabItems() {
    final LayoutInflater inflater = LayoutInflater.from(activityTestRule.getActivity());
    final TabLayout tabLayout = (TabLayout) inflater.inflate(R.layout.design_tabs_items, null);
    assertEquals(3, tabLayout.getTabCount());
    // Tab 0 has text, but no icon or custom view
    TabLayout.Tab tab = tabLayout.getTabAt(0);
    assertEquals(activityTestRule.getActivity().getString(R.string.tab_layout_text), tab.getText());
    assertNull(tab.getIcon());
    assertNull(tab.getCustomView());
    // Tab 1 has an icon, but no text or custom view
    tab = tabLayout.getTabAt(1);
    assertNull(tab.getText());
    assertNotNull(tab.getIcon());
    assertNull(tab.getCustomView());
    // Tab 2 has a custom view, but no text or icon
    tab = tabLayout.getTabAt(2);
    assertNull(tab.getText());
    assertNull(tab.getIcon());
    assertNotNull(tab.getCustomView());
    assertEquals(R.id.my_custom_tab, tab.getCustomView().getId());
}
Also used : 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 2 with UiThreadTest

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

the class TabLayoutTest method testTabWithCustomLayoutSelection1.

@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);
}
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 3 with UiThreadTest

use of android.support.test.annotation.UiThreadTest in project RxBinding by JakeWharton.

the class RxNestedScrollViewTest method scrollChangeEvents.

@Test
@UiThreadTest
public void scrollChangeEvents() {
    RecordingObserver<ViewScrollChangeEvent> o = new RecordingObserver<>();
    RxNestedScrollView.scrollChangeEvents(view).subscribe(o);
    o.assertNoMoreEvents();
    view.scrollTo(1000, 0);
    ViewScrollChangeEvent event = o.takeNext();
    assertSame(view, event.view());
    assertEquals(1000, event.scrollX());
    assertEquals(0, event.scrollY());
    assertEquals(0, event.oldScrollX());
    assertEquals(0, event.oldScrollY());
    o.dispose();
    view.scrollTo(2000, 0);
    o.assertNoMoreEvents();
}
Also used : ViewScrollChangeEvent(com.jakewharton.rxbinding2.view.ViewScrollChangeEvent) RecordingObserver(com.jakewharton.rxbinding2.RecordingObserver) UiThreadTest(android.support.test.annotation.UiThreadTest) Test(org.junit.Test) UiThreadTest(android.support.test.annotation.UiThreadTest)

Example 4 with UiThreadTest

use of android.support.test.annotation.UiThreadTest in project RxBinding by JakeWharton.

the class RxViewTest method touches.

@Test
@UiThreadTest
public void touches() {
    RecordingObserver<MotionEvent> o = new RecordingObserver<>();
    RxView.touches(view).subscribe(o);
    o.assertNoMoreEvents();
    view.dispatchTouchEvent(motionEventAtPosition(view, ACTION_DOWN, 0, 50));
    MotionEvent event1 = o.takeNext();
    assertEquals(ACTION_DOWN, event1.getAction());
    view.dispatchTouchEvent(motionEventAtPosition(view, ACTION_MOVE, 1, 50));
    MotionEvent event2 = o.takeNext();
    assertEquals(ACTION_MOVE, event2.getAction());
    o.dispose();
    view.dispatchTouchEvent(motionEventAtPosition(view, ACTION_UP, 1, 50));
    o.assertNoMoreEvents();
}
Also used : RecordingObserver(com.jakewharton.rxbinding2.RecordingObserver) MotionEvent(android.view.MotionEvent) UiThreadTest(android.support.test.annotation.UiThreadTest) Test(org.junit.Test) UiThreadTest(android.support.test.annotation.UiThreadTest)

Example 5 with UiThreadTest

use of android.support.test.annotation.UiThreadTest in project RxBinding by JakeWharton.

the class RxViewTest method hovers.

@Test
@UiThreadTest
public void hovers() {
    RecordingObserver<MotionEvent> o = new RecordingObserver<>();
    RxView.hovers(view).subscribe(o);
    o.assertNoMoreEvents();
    view.dispatchGenericMotionEvent(hoverMotionEventAtPosition(view, ACTION_HOVER_ENTER, 0, 50));
    MotionEvent event1 = o.takeNext();
    assertEquals(ACTION_HOVER_ENTER, event1.getAction());
    view.dispatchGenericMotionEvent(hoverMotionEventAtPosition(view, ACTION_HOVER_MOVE, 1, 50));
    MotionEvent event2 = o.takeNext();
    assertEquals(ACTION_HOVER_MOVE, event2.getAction());
    o.dispose();
    view.dispatchGenericMotionEvent(hoverMotionEventAtPosition(view, ACTION_HOVER_EXIT, 1, 50));
    o.assertNoMoreEvents();
}
Also used : RecordingObserver(com.jakewharton.rxbinding2.RecordingObserver) MotionEvent(android.view.MotionEvent) 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