Created
May 3, 2021 18:16
-
-
Save NinoDLC/4ce49489ebbb71c4ea9c32b6972e9b13 to your computer and use it in GitHub Desktop.
This file contains 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
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