Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save NinoDLC/4ce49489ebbb71c4ea9c32b6972e9b13 to your computer and use it in GitHub Desktop.
Save NinoDLC/4ce49489ebbb71c4ea9c32b6972e9b13 to your computer and use it in GitHub Desktop.
import android.view.View;
import androidx.recyclerview.widget.RecyclerView;
import androidx.test.espresso.NoMatchingViewException;
import androidx.test.espresso.ViewAssertion;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
public class RecyclerViewItemCountAssertion implements ViewAssertion {
private final int expectedCount;
public RecyclerViewItemCountAssertion(int expectedCount) {
this.expectedCount = expectedCount;
}
@Override
public void check(View view, NoMatchingViewException noViewFoundException) {
if (noViewFoundException != null) {
throw noViewFoundException;
}
RecyclerView recyclerView = (RecyclerView) view;
if (recyclerView.getAdapter() != null) {
assertThat(recyclerView.getAdapter().getItemCount(), is(expectedCount));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment