Created
October 13, 2018 23:14
-
-
Save cdmunoz/abd1c329b406b56f61392dfcf802ffb0 to your computer and use it in GitHub Desktop.
RecyclerViewSizeMatcher: Custom Espresso Matcher to check the size of a RecyclerView
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static Matcher<View> recyclerViewSizeMatcher(final int matcherSize) { | |
return new BoundedMatcher<View, RecyclerView>(RecyclerView.class) { | |
@Override | |
public void describeTo(Description description) { | |
description.appendText("with list size: " + matcherSize); | |
} | |
@Override | |
protected boolean matchesSafely(RecyclerView recyclerView) { | |
return matcherSize == recyclerView.getAdapter().getItemCount(); | |
} | |
}; | |
} | |
//how to use it: | |
onView(withId(R.id.my_list_recycler)).check(matches(recyclerViewSizeMatcher(4))); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment