|
20 | 20 | import static androidx.test.espresso.Espresso.onView; |
21 | 21 | import static androidx.test.espresso.action.ViewActions.click; |
22 | 22 | import static androidx.test.espresso.assertion.ViewAssertions.matches; |
| 23 | +import static androidx.test.espresso.matcher.ViewMatchers.hasDescendant; |
23 | 24 | import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; |
24 | 25 | import static androidx.test.espresso.matcher.ViewMatchers.withText; |
25 | 26 |
|
26 | 27 | import androidx.test.core.app.ActivityScenario; |
27 | 28 | import androidx.test.espresso.contrib.RecyclerViewActions; |
28 | 29 | import androidx.test.espresso.matcher.ViewMatchers; |
| 30 | +import androidx.test.espresso.PerformException; |
29 | 31 | import androidx.test.ext.junit.rules.ActivityScenarioRule; |
30 | 32 | import androidx.test.filters.LargeTest; |
31 | 33 | import androidx.test.ext.junit.runners.AndroidJUnit4; |
@@ -55,16 +57,14 @@ public class RecyclerViewSampleTest { |
55 | 57 | @Rule |
56 | 58 | public ActivityScenarioRule<MainActivity> activityScenarioRule = |
57 | 59 | new ActivityScenarioRule<MainActivity>(MainActivity.class); |
58 | | - |
59 | | - @Test |
60 | | - public void itemWithText_exists() { |
61 | | - String itemElementText = activityRule.getActivity().getResources() |
62 | | - .getString(R.string.item_element_text); |
63 | 60 |
|
64 | | - // scrollTo will fail if no item matches. |
| 61 | + @Test(expected = PerformException.class) |
| 62 | + public void itemWithText_doesNotExist() { |
| 63 | + // Attempt to scroll to an item that contains the special text. |
65 | 64 | onView(ViewMatchers.withId(R.id.recyclerView)) |
| 65 | + // scrollTo will fail the test if no item matches. |
66 | 66 | .perform(RecyclerViewActions.scrollTo( |
67 | | - hasDescendant(withText(itemElementText)) |
| 67 | + hasDescendant(withText("not in the list")) |
68 | 68 | )); |
69 | 69 | } |
70 | 70 |
|
|
0 commit comments