Search in sources :

Example 1 with AdaptedData

use of com.google.android.apps.common.testing.ui.espresso.action.AdapterViewProtocol.AdaptedData in project double-espresso by JakeWharton.

the class DataInteraction method displayingData.

private Matcher<View> displayingData(final Matcher<View> adapterMatcher, final Matcher<Object> dataMatcher, final AdapterViewProtocol adapterViewProtocol, final AdapterDataLoaderAction adapterDataLoaderAction) {
    checkNotNull(adapterMatcher);
    checkNotNull(dataMatcher);
    checkNotNull(adapterViewProtocol);
    return new TypeSafeMatcher<View>() {

        @Override
        public void describeTo(Description description) {
            description.appendText(" displaying data matching: ");
            dataMatcher.describeTo(description);
            description.appendText(" within adapter view matching: ");
            adapterMatcher.describeTo(description);
        }

        @SuppressWarnings("unchecked")
        @Override
        public boolean matchesSafely(View view) {
            ViewParent parent = view.getParent();
            while (parent != null && !(parent instanceof AdapterView)) {
                parent = parent.getParent();
            }
            if (parent != null && adapterMatcher.matches(parent)) {
                Optional<AdaptedData> data = adapterViewProtocol.getDataRenderedByView((AdapterView<? extends Adapter>) parent, view);
                if (data.isPresent()) {
                    return adapterDataLoaderAction.getAdaptedData().opaqueToken.equals(data.get().opaqueToken);
                }
            }
            return false;
        }
    };
}
Also used : TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) ViewParent(android.view.ViewParent) AdapterView(android.widget.AdapterView) AdaptedData(com.google.android.apps.common.testing.ui.espresso.action.AdapterViewProtocol.AdaptedData) Espresso.onView(com.google.android.apps.common.testing.ui.espresso.Espresso.onView) View(android.view.View) AdapterView(android.widget.AdapterView)

Aggregations

View (android.view.View)1 ViewParent (android.view.ViewParent)1 AdapterView (android.widget.AdapterView)1 Espresso.onView (com.google.android.apps.common.testing.ui.espresso.Espresso.onView)1 AdaptedData (com.google.android.apps.common.testing.ui.espresso.action.AdapterViewProtocol.AdaptedData)1 Description (org.hamcrest.Description)1 TypeSafeMatcher (org.hamcrest.TypeSafeMatcher)1