Search in sources :

Example 1 with StringDescription

use of org.hamcrest.StringDescription in project JsonPath by jayway.

the class IsJsonFileTest method shouldDescribeMismatchOfValidJson.

@Test
public void shouldDescribeMismatchOfValidJson() {
    Matcher<File> matcher = isJsonFile(withPathEvaluatedTo(true));
    Description description = new StringDescription();
    matcher.describeMismatch(BOOKS_JSON, description);
    assertThat(description.toString(), containsString(MISMATCHED_TEXT));
}
Also used : Description(org.hamcrest.Description) StringDescription(org.hamcrest.StringDescription) StringDescription(org.hamcrest.StringDescription) File(java.io.File) JsonPathMatchers.isJsonFile(com.jayway.jsonpath.matchers.JsonPathMatchers.isJsonFile) ResourceHelpers.resourceAsFile(com.jayway.jsonpath.matchers.helpers.ResourceHelpers.resourceAsFile) Test(org.junit.Test)

Example 2 with StringDescription

use of org.hamcrest.StringDescription in project JsonPath by jayway.

the class IsJsonStringTest method shouldDescribeMismatchOfValidJson.

@Test
public void shouldDescribeMismatchOfValidJson() {
    Matcher<String> matcher = isJsonString(withPathEvaluatedTo(true));
    Description description = new StringDescription();
    matcher.describeMismatch(BOOKS_JSON, description);
    assertThat(description.toString(), containsString(MISMATCHED_TEXT));
}
Also used : Description(org.hamcrest.Description) StringDescription(org.hamcrest.StringDescription) StringDescription(org.hamcrest.StringDescription) JsonPathMatchers.isJsonString(com.jayway.jsonpath.matchers.JsonPathMatchers.isJsonString) Test(org.junit.Test)

Example 3 with StringDescription

use of org.hamcrest.StringDescription in project JsonPath by jayway.

the class IsJsonTest method shouldDescribeMismatchOfInvalidJson.

@Test
public void shouldDescribeMismatchOfInvalidJson() {
    Matcher<Object> matcher = isJson(withPathEvaluatedTo(true));
    Description description = new StringDescription();
    matcher.describeMismatch("invalid-json", description);
    assertThat(description.toString(), containsString("\"invalid-json\""));
}
Also used : Description(org.hamcrest.Description) StringDescription(org.hamcrest.StringDescription) StringDescription(org.hamcrest.StringDescription) Test(org.junit.Test)

Example 4 with StringDescription

use of org.hamcrest.StringDescription in project junit4 by junit-team.

the class StackTracesTest method assertHasTrimmedTrace.

private static void assertHasTrimmedTrace(Failure failure, StringMatcher... matchers) {
    String trimmedTrace = failure.getTrimmedTrace();
    String[] lines = trimmedTrace.split(EOL);
    int index = 0;
    for (; index < lines.length && index < matchers.length; index++) {
        String line = lines[index];
        StringMatcher matcher = matchers[index];
        assertThat(line, matcher);
    }
    if (index < lines.length) {
        String extraLine = lines[index];
        fail("Extra line in trimmed trace: " + extraLine);
    } else if (index < matchers.length) {
        StringDescription description = new StringDescription();
        matchers[index].describeTo(description);
        fail("Missing line in trimmed trace: " + description.toString());
    }
}
Also used : StringDescription(org.hamcrest.StringDescription)

Example 5 with StringDescription

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

the class AssertableLogProvider method assertContainsMessageMatching.

public void assertContainsMessageMatching(Matcher<String> messageMatcher) {
    synchronized (logCalls) {
        for (LogCall logCall : logCalls) {
            if (messageMatcher.matches(logCall.message)) {
                return;
            }
        }
        StringDescription description = new StringDescription();
        description.appendDescriptionOf(messageMatcher);
        fail(format("Expected at least one log statement with message as %s, but none found. Actual log calls were:\n%s", description.toString(), serialize(logCalls.iterator())));
    }
}
Also used : StringDescription(org.hamcrest.StringDescription)

Aggregations

StringDescription (org.hamcrest.StringDescription)32 Description (org.hamcrest.Description)22 Test (org.junit.Test)15 JsonPathMatchers.isJsonFile (com.jayway.jsonpath.matchers.JsonPathMatchers.isJsonFile)3 JsonPathMatchers.isJsonString (com.jayway.jsonpath.matchers.JsonPathMatchers.isJsonString)3 ResourceHelpers.resourceAsFile (com.jayway.jsonpath.matchers.helpers.ResourceHelpers.resourceAsFile)3 File (java.io.File)3 View (android.view.View)2 AdapterView (android.widget.AdapterView)2 Adapter (android.widget.Adapter)1 TextView (android.widget.TextView)1 ViewAssertion (com.google.android.apps.common.testing.ui.espresso.ViewAssertion)1 ScrollToAction (com.google.android.apps.common.testing.ui.espresso.action.ScrollToAction)1 Optional (com.google.common.base.Optional)1 AssertionFailedError (junit.framework.AssertionFailedError)1 AnnotatedElementDeclaration (org.freud.analysed.javasource.AnnotatedElementDeclaration)1 Annotation (org.freud.analysed.javasource.Annotation)1 FreudExtendedMatcher (org.freud.java.matcher.FreudExtendedMatcher)1