Android UI Test — Espresso Matcher for ImageView
Daniele Bottillo
39623

Very good! Congratulations.

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

@Override
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()
.equals(expectedDrawable.getConstantState());
}