Search in sources :

Example 66 with TypeSafeMatcher

use of org.hamcrest.TypeSafeMatcher in project kickmaterial by byoutline.

the class CustomMatchers method withErrorSet.

public static Matcher<View> withErrorSet(@NonNull final String expected) {
    if (expected == null) {
        throw new AssertionError("Null string passed");
    }
    return new TypeSafeMatcher<View>() {

        @Override
        public boolean matchesSafely(View view) {
            if (!(view instanceof EditText)) {
                return false;
            }
            EditText editText = (EditText) view;
            CharSequence error = editText.getError();
            if (error == null) {
                return false;
            }
            return expected.equals(error.toString());
        }

        @Override
        public void describeTo(Description description) {
            description.appendText("view should have error: ").appendValue(expected).appendText(" set");
        }
    };
}
Also used : EditText(android.widget.EditText) TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) View(android.view.View)

Example 67 with TypeSafeMatcher

use of org.hamcrest.TypeSafeMatcher in project material-components-android by material-components.

the class TestUtilsMatchers method isActionViewOf.

/**
   * Returns a matcher that matches the action view of the specified menu item.
   *
   * @param menu The menu
   * @param id The ID of the menu item
   */
public static Matcher<View> isActionViewOf(@NonNull final Menu menu, @IdRes final int id) {
    return new TypeSafeMatcher<View>() {

        private Resources resources;

        @Override
        protected boolean matchesSafely(View view) {
            resources = view.getResources();
            MenuItemImpl item = (MenuItemImpl) menu.findItem(id);
            return item != null && item.getActionView() == view;
        }

        @Override
        public void describeTo(Description description) {
            String name;
            if (resources != null) {
                name = resources.getResourceName(id);
            } else {
                name = Integer.toString(id);
            }
            description.appendText("is action view of menu item " + name);
        }
    };
}
Also used : MenuItemImpl(android.support.v7.view.menu.MenuItemImpl) TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) Resources(android.content.res.Resources) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView)

Example 68 with TypeSafeMatcher

use of org.hamcrest.TypeSafeMatcher in project material-components-android by material-components.

the class TestUtilsMatchers method isChildOfA.

/**
   * Returns a matcher that matches {@link View}s based on the given parent type.
   *
   * @param parentMatcher the type of the parent to match on
   */
public static Matcher<View> isChildOfA(final Matcher<View> parentMatcher) {
    return new TypeSafeMatcher<View>() {

        @Override
        public void describeTo(Description description) {
            description.appendText("is child of a: ");
            parentMatcher.describeTo(description);
        }

        @Override
        public boolean matchesSafely(View view) {
            final ViewParent viewParent = view.getParent();
            if (!(viewParent instanceof View)) {
                return false;
            }
            if (parentMatcher.matches(viewParent)) {
                return true;
            }
            return false;
        }
    };
}
Also used : TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) ViewParent(android.view.ViewParent) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView)

Example 69 with TypeSafeMatcher

use of org.hamcrest.TypeSafeMatcher in project neo4j by neo4j.

the class QueryResultsSerializationTest method restContainsNestedDeleted.

/**
     * This matcher is hardcoded to check for a list containing one deleted node and one map with a deleted node mapped to the key `someKey`.
     */
public static Matcher<? super Response> restContainsNestedDeleted() {
    return new TypeSafeMatcher<Response>() {

        @Override
        protected boolean matchesSafely(HTTP.Response response) {
            try {
                JsonNode list = TransactionMatchers.getJsonNodeWithName(response, "rest").iterator().next();
                assertThat(list.get(0).get("metadata").get("deleted").asBoolean(), equalTo(Boolean.TRUE));
                assertThat(list.get(1).get("someKey").get("metadata").get("deleted").asBoolean(), equalTo(Boolean.TRUE));
                return true;
            } catch (JsonParseException e) {
                return false;
            }
        }

        @Override
        public void describeTo(Description description) {
        }
    };
}
Also used : Response(org.neo4j.test.server.HTTP.Response) TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) JsonNode(org.codehaus.jackson.JsonNode) JsonParseException(org.neo4j.server.rest.domain.JsonParseException)

Example 70 with TypeSafeMatcher

use of org.hamcrest.TypeSafeMatcher in project neo4j by neo4j.

the class TransportTestUtil method eventuallyReceives.

public static Matcher<TransportConnection> eventuallyReceives(final Matcher<ResponseMessage>... messages) {
    return new TypeSafeMatcher<TransportConnection>() {

        @Override
        protected boolean matchesSafely(TransportConnection conn) {
            try {
                for (Matcher<ResponseMessage> matchesMessage : messages) {
                    final ResponseMessage message = receiveOneResponseMessage(conn);
                    assertThat(message, matchesMessage);
                }
                return true;
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }

        @Override
        public void describeTo(Description description) {
            description.appendValueList("Messages[", ",", "]", messages);
        }
    };
}
Also used : TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) TransportConnection(org.neo4j.bolt.v1.transport.socket.client.TransportConnection) Description(org.hamcrest.Description) ResponseMessage(org.neo4j.bolt.v1.messaging.message.ResponseMessage) IOException(java.io.IOException)

Aggregations

TypeSafeMatcher (org.hamcrest.TypeSafeMatcher)123 Description (org.hamcrest.Description)120 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