Search in sources :

Example 16 with Description

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

the class TransactionMatchers method hasErrors.

public static Matcher<? super HTTP.Response> hasErrors(final Status... expectedErrors) {
    return new TypeSafeMatcher<HTTP.Response>() {

        @Override
        protected boolean matchesSafely(HTTP.Response response) {
            try {
                Iterator<JsonNode> errors = response.get("errors").iterator();
                Iterator<Status> expected = iterator(expectedErrors);
                while (expected.hasNext()) {
                    assertTrue(errors.hasNext());
                    assertThat(errors.next().get("code").asText(), equalTo(expected.next().code().serialize()));
                }
                if (errors.hasNext()) {
                    JsonNode error = errors.next();
                    fail("Expected no more errors, but got " + error.get("code") + " - '" + error.get("message") + "'.");
                }
                return true;
            } catch (JsonParseException e) {
                return false;
            }
        }

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

Example 17 with Description

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

the class TransactionMatchers method restContainsDeletedEntities.

public static Matcher<? super HTTP.Response> restContainsDeletedEntities(final int amount) {
    return new TypeSafeMatcher<HTTP.Response>() {

        @Override
        protected boolean matchesSafely(HTTP.Response response) {
            try {
                Iterator<JsonNode> entities = getJsonNodeWithName(response, "rest").iterator();
                for (int i = 0; i < amount; ++i) {
                    assertTrue(entities.hasNext());
                    JsonNode node = entities.next();
                    assertThat(node.get("metadata").get("deleted").asBoolean(), equalTo(Boolean.TRUE));
                }
                if (entities.hasNext()) {
                    fail("Expected no more entities");
                }
                return true;
            } catch (JsonParseException e) {
                return false;
            }
        }

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

Example 18 with Description

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

the class TransactionMatchers method rowContainsDeletedEntitiesInPath.

public static Matcher<? super HTTP.Response> rowContainsDeletedEntitiesInPath(final int nodes, final int rels) {
    return new TypeSafeMatcher<HTTP.Response>() {

        @Override
        protected boolean matchesSafely(HTTP.Response response) {
            try {
                Iterator<JsonNode> meta = getJsonNodeWithName(response, "meta").iterator();
                int nodeCounter = 0;
                int relCounter = 0;
                assertTrue("Expected to find a JSON node, but there was none", meta.hasNext());
                JsonNode node = meta.next();
                assertTrue("Expected the node to be a list (for a path)", node.isArray());
                for (JsonNode inner : node) {
                    String type = inner.get("type").getTextValue();
                    switch(type) {
                        case "node":
                            if (inner.get("deleted").asBoolean()) {
                                ++nodeCounter;
                            }
                            break;
                        case "relationship":
                            if (inner.get("deleted").asBoolean()) {
                                ++relCounter;
                            }
                            break;
                        default:
                            fail("Unexpected type: " + type);
                            break;
                    }
                }
                assertEquals(nodes, nodeCounter);
                assertEquals(rels, relCounter);
                return true;
            } catch (JsonParseException e) {
                return false;
            }
        }

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

Example 19 with Description

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

the class TransactionMatchers method graphContainsDeletedNodes.

public static Matcher<? super HTTP.Response> graphContainsDeletedNodes(final int amount) {
    return new TypeSafeMatcher<HTTP.Response>() {

        @Override
        protected boolean matchesSafely(HTTP.Response response) {
            try {
                Iterator<JsonNode> nodes = getJsonNodeWithName(response, "graph").get("nodes").iterator();
                for (int i = 0; i < amount; ++i) {
                    assertTrue(nodes.hasNext());
                    JsonNode node = nodes.next();
                    assertThat(node.get("deleted").asBoolean(), equalTo(Boolean.TRUE));
                }
                while (nodes.hasNext()) {
                    JsonNode node = nodes.next();
                    assertNull(node.get("deleted"));
                }
                return true;
            } catch (JsonParseException e) {
                return false;
            }
        }

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

Example 20 with Description

use of org.hamcrest.Description in project querydsl by querydsl.

the class PathMatcherTest method mismatch.

@Test
public void mismatch() {
    Car car = new Car();
    car.setHorsePower(123);
    Description mismatchDescription = new StringDescription();
    hasValue($.horsePower, equalTo(321)).describeMismatch(car, mismatchDescription);
    assertEquals("value \"car.horsePower\" was <123>", mismatchDescription.toString());
}
Also used : Description(org.hamcrest.Description) StringDescription(org.hamcrest.StringDescription) StringDescription(org.hamcrest.StringDescription) Test(org.junit.Test)

Aggregations

Description (org.hamcrest.Description)117 Test (org.junit.Test)37 TypeSafeMatcher (org.hamcrest.TypeSafeMatcher)35 StringDescription (org.hamcrest.StringDescription)26 BaseMatcher (org.hamcrest.BaseMatcher)25 View (android.view.View)22 ViewParent (android.view.ViewParent)11 TextView (android.widget.TextView)11 ViewGroup (android.view.ViewGroup)8 Expectations (org.jmock.Expectations)8 URL (java.net.URL)7 Matcher (org.hamcrest.Matcher)7 Invocation (org.jmock.api.Invocation)7 BoundedMatcher (android.support.test.espresso.matcher.BoundedMatcher)6 ImageView (android.widget.ImageView)6 File (java.io.File)6 IOException (java.io.IOException)6 URI (java.net.URI)6 List (java.util.List)6 JsonNode (org.codehaus.jackson.JsonNode)6