/** * Access item by index known by the adapter. * * @param index Item index in adapter. * * @return New element instance for action and assertions. * * @since Espresso Macchiato 0.5 */ public EspAdapterViewItem itemByIndex(int index) { return EspAdapterViewItem.byItemIndex(resourceId, index); }
/** * Create new instance based on adapter index. * * @param adapterViewId Adapter view containing this item. * @param index Item index for doing actions or assertions. * * @return New instance for actions and assertions. * * @since Espresso Macchiato 0.5 */ public static EspAdapterViewItem byItemIndex(int adapterViewId, int index) { return new EspAdapterViewItem(withId(adapterViewId), adapterViewId, index, Mode.byItemIndex); }
/** * Access item by his visible index. * * @param index That is the index which a human can see. * * @return New element instance for action and assertions. * * @since Espresso Macchiato 0.5 */ public EspAdapterViewItem itemByVisibleIndex(int index) { return EspAdapterViewItem.byVisibleIndex(resourceId, index); } }
@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 testItemByVisibleIndex() { espAdapterView.itemByVisibleIndex(0).assertIsDisplayedOnScreen(); } }
@Test @SuppressWarnings("deprecation") public void testByAllNotSupported() { exception.expect(UnsupportedOperationException.class); EspAdapterViewItem.byAll(); }
@Test @SuppressWarnings("deprecation") public void testByIdNotSupported() { exception.expect(UnsupportedOperationException.class); EspAdapterViewItem.byId(0); } }
@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 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 @SuppressWarnings({"unused", "UnusedAssignment"}) public void testJustForCoverage() { EspListViewItem espListViewItem; espListViewItem = EspListViewItem.byItemIndex(0, 0); espListViewItem = EspListViewItem.byVisibleIndex(0, 0); new MyEspListViewItem(EspAdapterViewItem.byItemIndex(0, 0)); }
@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(); }
/** * Create new instance based on visible index. * * @param adapterViewId Adapter view containing this item. * @param index Item index for doing actions or assertions. * * @return New instance for actions and assertions. * * @since Espresso Macchiato 0.5 */ public static EspAdapterViewItem byVisibleIndex(int adapterViewId, int index) { return new EspAdapterViewItem(EspAdapterViewItemMatcher.withAdapterView(withId(adapterViewId)).atChildIndex(index), adapterViewId, index, Mode.byVisibleIndex); }