use of android.support.test.espresso.matcher.BoundedMatcher in project material-components-android by material-components.
the class TestUtilsMatchers method withStartDrawableFilledWith.
/**
* Returns a matcher that matches TextViews whose start drawable is filled with the specified fill
* color.
*/
public static Matcher withStartDrawableFilledWith(@ColorInt final int fillColor, final int allowedComponentVariance) {
return new BoundedMatcher<View, TextView>(TextView.class) {
private String failedCheckDescription;
@Override
public void describeTo(final Description description) {
description.appendText(failedCheckDescription);
}
@Override
public boolean matchesSafely(final TextView view) {
final Drawable[] compoundDrawables = view.getCompoundDrawables();
final boolean isRtl = (ViewCompat.getLayoutDirection(view) == ViewCompat.LAYOUT_DIRECTION_RTL);
final Drawable startDrawable = isRtl ? compoundDrawables[2] : compoundDrawables[0];
if (startDrawable == null) {
failedCheckDescription = "no start drawable";
return false;
}
try {
final Rect bounds = startDrawable.getBounds();
TestUtils.assertAllPixelsOfColor("", startDrawable, bounds.width(), bounds.height(), true, fillColor, allowedComponentVariance, true);
} catch (Throwable t) {
failedCheckDescription = t.getMessage();
return false;
}
return true;
}
};
}
Aggregations