/** * Create new instance matching an element with given resourceId. * * @param resourceId Identifier for this element. * * @return New element instance for action and assertions. * * @since Espresso Macchiato 0.3 */ public static EspAdapterView byId(int resourceId) { return new EspAdapterView(resourceId); }
/** * Check that the views adapter contains the expected count of items. * * This counts the items existing in adapter and not the visible items. * Header and footer are count as list items. * * @param expected Zero for no items or a positive number. * * @since Espresso Macchiato 0.3 */ public void assertItemCountIs(int expected) { findView().check(new AdapterViewItemCountAssertion(expected)); }
@Test public void testItemByVisibleIndex() { espAdapterView.itemByVisibleIndex(0).assertIsDisplayedOnScreen(); } }
@Test public void testScrollTo() { espAdapterView.itemByIndex(99).scrollTo(); espAdapterView.itemByIndex(20).scrollTo(); EspTextView espTextView = new EspTextView(espAdapterView.itemByVisibleIndex(0).baseMatcherForItemChild(withId(LongListActivity.itemTextViewId))); espTextView.assertTextIs("item: 20"); }
@Test public void testCustomBaseMatcher() { //espAdapterView = new EspAdapterView(allOf(withId(LongListActivity.listViewId), isDisplayed())); espAdapterView.assertIsVisible(); }
@Test public void testAssertItemCountIs() { espAdapterView.assertItemCountIs(LongListActivity.listViewItemCount); }
@Test public void testBaseMatcherForItemChildNotSupported() { exception.expect(UnsupportedOperationException.class); exception.expectMessage("Method only supported when item accessed byVisibleIndex"); espAdapterView.itemByIndex(0).baseMatcherForItemChild(withId(LongListActivity.itemTextViewId)); } }
@Test public void testAssertIsDisplayed() { espAdapterView.itemByVisibleIndex(0).assertIsDisplayedOnScreen(); }
@Test public void testById() { espAdapterView.assertIsVisible(); }
@Test public void testClickRow() { espAdapterView.itemByVisibleIndex(0).click(); espTextView.assertTextIs(String.valueOf(0)); } }
@Test public void testScrollToFailureNotSupported() { exception.expect(UnsupportedOperationException.class); exception.expectMessage("Method only supported when item accessed byItemIndex"); espAdapterView.itemByVisibleIndex(20).scrollTo(); }
@Test public void testItemByVisibleIndexFailureLessItems() { exception.expect(AssertionFailedError.class); exception.expectMessage("Requested child at index 20 but adapter view has only "); exception.expectMessage(" visible childs."); espAdapterView.itemByVisibleIndex(20).assertIsDisplayedOnScreen(); }