Basically I am trying to test that after login incorrectly I have an error showing in the email field.
The view is:
wrote a custom matcher
import android.view.View;
import com.google.android.material.textfield.TextInputLayout;
import org.hamcrest.Description;
import org.hamcrest.TypeSafeMatcher;
public class TextInputLayoutErrorMatcher extends TypeSafeMatcher{
private String expectedErrorText;
TextInputLayoutErrorMatcher(String expectedErrorText) {
this.expectedErrorText = expectedErrorText;
}
@Override
protected boolean matchesSafely(View item) {
if (!(item instanceof TextInputLayout)) {
return false;
}
CharSequence error = ((TextInputLayout) item).getError();
if (error == null) {
return false;
}
String hint = error.toString();
return expectedErrorText.equals(hint);
}
@Override
public void describeTo(Description description) {
description.appendText("with error text " + expectedErrorText);
}
}