Search in sources :

Example 11 with Description

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

the class MessageMatchers method msgFailure.

public static Matcher<ResponseMessage> msgFailure(final Status status, final String message) {
    return new TypeSafeMatcher<ResponseMessage>() {

        @Override
        protected boolean matchesSafely(ResponseMessage t) {
            assertThat(t, instanceOf(FailureMessage.class));
            FailureMessage msg = (FailureMessage) t;
            assertThat(msg.status(), equalTo(status));
            assertThat(msg.message(), containsString(message));
            return true;
        }

        @Override
        public void describeTo(Description description) {
            description.appendText("FAILURE");
        }
    };
}
Also used : TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) FailureMessage(org.neo4j.bolt.v1.messaging.message.FailureMessage) ResponseMessage(org.neo4j.bolt.v1.messaging.message.ResponseMessage)

Example 12 with Description

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

the class MessageMatchers method msgRecord.

public static Matcher<ResponseMessage> msgRecord(final Matcher<Record> matcher) {
    return new TypeSafeMatcher<ResponseMessage>() {

        @Override
        protected boolean matchesSafely(ResponseMessage t) {
            assertThat(t, instanceOf(RecordMessage.class));
            RecordMessage msg = (RecordMessage) t;
            assertThat(msg.record(), matcher);
            return true;
        }

        @Override
        public void describeTo(Description description) {
            description.appendText("RECORD ");
            description.appendDescriptionOf(matcher);
        }
    };
}
Also used : TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) ResponseMessage(org.neo4j.bolt.v1.messaging.message.ResponseMessage) RecordMessage(org.neo4j.bolt.v1.messaging.message.RecordMessage)

Example 13 with Description

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

the class BoltMatchers method hasTransaction.

public static Matcher<BoltStateMachine> hasTransaction() {
    return new BaseMatcher<BoltStateMachine>() {

        @Override
        public boolean matches(final Object item) {
            final BoltStateMachine machine = (BoltStateMachine) item;
            final StatementProcessor statementProcessor = machine.statementProcessor();
            return statementProcessor != null && statementProcessor.hasTransaction();
        }

        @Override
        public void describeTo(Description description) {
            description.appendText("no transaction");
        }
    };
}
Also used : Description(org.hamcrest.Description) BaseMatcher(org.hamcrest.BaseMatcher) BoltStateMachine(org.neo4j.bolt.v1.runtime.BoltStateMachine) StatementProcessor(org.neo4j.bolt.v1.runtime.StatementProcessor)

Example 14 with Description

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

the class TransactionMatchers method rowContainsDeletedEntities.

public static Matcher<? super HTTP.Response> rowContainsDeletedEntities(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;
                for (int i = 0; i < nodes + rels; ++i) {
                    assertTrue(meta.hasNext());
                    JsonNode node = meta.next();
                    assertThat(node.get("deleted").asBoolean(), equalTo(Boolean.TRUE));
                    String type = node.get("type").getTextValue();
                    switch(type) {
                        case "node":
                            ++nodeCounter;
                            break;
                        case "relationship":
                            ++relCounter;
                            break;
                        default:
                            fail("Unexpected type: " + type);
                            break;
                    }
                }
                assertEquals(nodes, nodeCounter);
                assertEquals(rels, relCounter);
                while (meta.hasNext()) {
                    JsonNode node = meta.next();
                    assertThat(node.get("deleted").asBoolean(), equalTo(Boolean.FALSE));
                }
                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 15 with Description

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

the class TransactionMatchers method graphContainsDeletedRelationships.

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

        @Override
        protected boolean matchesSafely(HTTP.Response response) {
            try {
                Iterator<JsonNode> relationships = getJsonNodeWithName(response, "graph").get("relationships").iterator();
                for (int i = 0; i < amount; ++i) {
                    assertTrue(relationships.hasNext());
                    JsonNode node = relationships.next();
                    assertThat(node.get("deleted").asBoolean(), equalTo(Boolean.TRUE));
                }
                if (relationships.hasNext()) {
                    JsonNode node = relationships.next();
                    fail("Expected no more nodes, but got a node with id " + node.get("id"));
                }
                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)

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