Search in sources :

Example 86 with TypeSafeMatcher

use of org.hamcrest.TypeSafeMatcher 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)

Example 87 with TypeSafeMatcher

use of org.hamcrest.TypeSafeMatcher in project flink by apache.

the class S3RecoverableFsDataOutputStreamTest method hasContent.

private static TypeSafeMatcher<TestMultipartUpload> hasContent(final Collection<byte[]> expectedContents) throws IOException {
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    for (byte[] c : expectedContents) {
        stream.write(c);
    }
    byte[] expectedContent = stream.toByteArray();
    return new TypeSafeMatcher<TestMultipartUpload>() {

        @Override
        protected boolean matchesSafely(TestMultipartUpload testMultipartUpload) {
            return Arrays.equals(testMultipartUpload.getPublishedContents(), expectedContent);
        }

        @Override
        public void describeTo(Description description) {
            description.appendText("a TestMultipartUpload with contents='").appendValue(expectedContent).appendText("'");
        }
    };
}
Also used : TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 88 with TypeSafeMatcher

use of org.hamcrest.TypeSafeMatcher in project chefly_android by chef-ly.

the class RecipeDetailTest method childAtPosition.

private static Matcher<View> childAtPosition(final Matcher<View> parentMatcher, final int position) {
    return new TypeSafeMatcher<View>() {

        @Override
        public void describeTo(Description description) {
            description.appendText("Child at position " + position + " in parent ");
            parentMatcher.describeTo(description);
        }

        @Override
        public boolean matchesSafely(View view) {
            ViewParent parent = view.getParent();
            return parent instanceof ViewGroup && parentMatcher.matches(parent) && view.equals(((ViewGroup) parent).getChildAt(position));
        }
    };
}
Also used : TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) ViewParent(android.view.ViewParent) ViewGroup(android.view.ViewGroup) Espresso.onView(android.support.test.espresso.Espresso.onView) View(android.view.View)

Example 89 with TypeSafeMatcher

use of org.hamcrest.TypeSafeMatcher in project SeriesGuide by UweTrottmann.

the class ShowsActivityTest method childAtPosition.

private static Matcher<View> childAtPosition(final Matcher<View> parentMatcher, final int position) {
    return new TypeSafeMatcher<View>() {

        @Override
        public void describeTo(Description description) {
            description.appendText("Child at position " + position + " in parent ");
            parentMatcher.describeTo(description);
        }

        @Override
        public boolean matchesSafely(View view) {
            ViewParent parent = view.getParent();
            return parent instanceof ViewGroup && parentMatcher.matches(parent) && view.equals(((ViewGroup) parent).getChildAt(position));
        }
    };
}
Also used : TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) ViewMatchers.withContentDescription(androidx.test.espresso.matcher.ViewMatchers.withContentDescription) ViewParent(android.view.ViewParent) ViewGroup(android.view.ViewGroup) View(android.view.View) Espresso.onView(androidx.test.espresso.Espresso.onView)

Example 90 with TypeSafeMatcher

use of org.hamcrest.TypeSafeMatcher in project Team-Plant-Power by Alexander1994.

the class HistoricalLightTest method childAtPosition.

private static Matcher<View> childAtPosition(final Matcher<View> parentMatcher, final int position) {
    return new TypeSafeMatcher<View>() {

        @Override
        public void describeTo(Description description) {
            description.appendText("Child at position " + position + " in parent ");
            parentMatcher.describeTo(description);
        }

        @Override
        public boolean matchesSafely(View view) {
            ViewParent parent = view.getParent();
            return parent instanceof ViewGroup && parentMatcher.matches(parent) && view.equals(((ViewGroup) parent).getChildAt(position));
        }
    };
}
Also used : TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) ViewParent(android.view.ViewParent) ViewGroup(android.view.ViewGroup) Espresso.onView(android.support.test.espresso.Espresso.onView) View(android.view.View)

Aggregations

TypeSafeMatcher (org.hamcrest.TypeSafeMatcher)124 Description (org.hamcrest.Description)121 View (android.view.View)62 ViewParent (android.view.ViewParent)43 ViewGroup (android.view.ViewGroup)40 Espresso.onView (android.support.test.espresso.Espresso.onView)26 Espresso.onView (androidx.test.espresso.Espresso.onView)11 TextView (android.widget.TextView)10 Resources (android.content.res.Resources)9 Test (org.junit.Test)9 ViewMatchers.withContentDescription (android.support.test.espresso.matcher.ViewMatchers.withContentDescription)8 RecyclerView (androidx.recyclerview.widget.RecyclerView)7 ArrayList (java.util.ArrayList)6 JsonNode (org.codehaus.jackson.JsonNode)6 JsonParseException (org.neo4j.server.rest.domain.JsonParseException)6 HTTP (org.neo4j.test.server.HTTP)6 ViewMatchers.withContentDescription (androidx.test.espresso.matcher.ViewMatchers.withContentDescription)5 List (java.util.List)5 StringDescription (org.hamcrest.StringDescription)5 AdapterView (android.widget.AdapterView)4