package com.hitherejoe.androidtvboilerplate.util;
import android.text.TextUtils;
import android.view.View;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;
import static android.support.test.espresso.core.deps.guava.base.Preconditions.checkArgument;
import static android.support.test.espresso.matcher.ViewMatchers.isDescendantOfA;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static org.hamcrest.Matchers.allOf;
public class CustomMatchers {
public static Matcher<View> withItemText(final String itemText, final int parentId) {
checkArgument(!TextUtils.isEmpty(itemText), "itemText cannot be null or empty");
return new TypeSafeMatcher<View>() {
@Override
public boolean matchesSafely(View item) {
return allOf(isDescendantOfA(withId(parentId)),
withText(itemText)).matches(item);
}
@Override
public void describeTo(Description description) {
description.appendText("is isDescendantOfA RecyclerView with text " + itemText);
}
};
}
}