Skip to content

Instantly share code, notes, and snippets.

@cdmunoz
Created October 13, 2018 23:14
Show Gist options
  • Save cdmunoz/abd1c329b406b56f61392dfcf802ffb0 to your computer and use it in GitHub Desktop.
Save cdmunoz/abd1c329b406b56f61392dfcf802ffb0 to your computer and use it in GitHub Desktop.
RecyclerViewSizeMatcher: Custom Espresso Matcher to check the size of a RecyclerView
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