Implementare un ViewMatcher personalizzato per testare le viste non supportate immediatamente.
Ecco un esempio di implementazione withError matcher per TextInputLayout
public static Matcher<View> withErrorInInputLayout(final Matcher<String> stringMatcher) {
checkNotNull(stringMatcher);
return new BoundedMatcher<View, TextInputLayout>(TextInputLayout.class) {
String actualError = "";
@Override
public void describeTo(Description description) {
description.appendText("with error: ");
stringMatcher.describeTo(description);
description.appendText("But got: " + actualText);
}
@Override
public boolean matchesSafely(TextInputLayout textInputLayout) {
CharSequence error = textInputLayout.getError();
if (error != null) {
actualError = error.toString();
return stringMatcher.matches(actualError);
}
return false;
}
};
}
public static Matcher<View> withErrorInInputLayout(final String string) {
return withErrorInInputLayout(is(string));
}
fonte
2016-05-06 17:43:56