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());
}
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);
}
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();
}
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();
}
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();
}
Aggregations