Android Espresso - How to check EditText hint?

android, android-espresso

Solution

Looks like I figured it out. Basically, you need to create your own matcher:

public static Matcher<View> withHint(final String expectedHint) {
    return new TypeSafeMatcher<View>() {

        @Override
        public boolean matchesSafely(View view) {
            if (!(view instanceof EditText)) {
                return false;
            }

            String hint = ((EditText) view).getHint().toString();

            return expectedHint.equals(hint);
        }

        @Override
        public void describeTo(Description description) {
        }
    };
}

Then you can use it:

onView(withId(R.id.locationInput)).check(matches(withHint("Location (Optional)")));

Problem

I'm starting to play with Espresso, got my basic tests running. Now trying to figure out how to check that my edit text has a specific hint text? Thanks. `onView(withId(R.id.locationInput)).check(matches...?)`

Original source