Android UI Test — Espresso Matcher for ImageView
Daniele Bottillo

Very good! Congratulations.

Just an improvement. You can make it more general for use with whatever view that has a background Drawable.

protected boolean matchesSafely(View item) {
Resources resources = item.getContext().getResources();
Drawable expectedDrawable = resources.getDrawable(expectedId);

if (expectedDrawable == null) return false;
Drawable itemDrawable = item.getBackground();
    return itemDrawable.getConstantState()