Last active
September 6, 2016 01:51
-
-
Save heitorcolangelo/7f621a888c4ed5ec15529c6c05ddcdb3 to your computer and use it in GitHub Desktop.
To match textColor of a TextView
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
public class TextColorMatcher { | |
private TextColorMatcher(){} | |
public static Matcher<View> withTextColor(@ColorInt final int expectedColor) { | |
return new BoundedMatcher<View, TextView>(TextView.class) { | |
int currentColor = 0; | |
@Override | |
public void describeTo(Description description) { | |
description.appendText("expected TextColor: ") | |
.appendValue(Integer.toHexString(expectedColor)); | |
description.appendText(" current TextColor: ") | |
.appendValue(Integer.toHexString(currentColor)); | |
} | |
@Override | |
protected boolean matchesSafely(TextView item) { | |
if(currentColor == 0) | |
currentColor = item.getCurrentTextColor(); | |
return currentColor == expectedColor; | |
} | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment