Package org.hamcrest

Examples of org.hamcrest.StringDescription


        for (ScheduledItem item : schedule) {
            if (item.getScheduleTime().equals(scheduledTime) && matcher.matches(item.getEvent())) {
                return;
            }
        }
        Description expected = new StringDescription();
        Description actual = new StringDescription();
        matcher.describeTo(expected);
        describe(eventScheduler.getScheduledItems(), actual);
        throw new AxonAssertionError(String.format(
                "Did not find an event at the given schedule. \nExpected:\n<%s> at <%s>\nGot:%s\n",
                expected, scheduledTime, actual));
View Full Code Here


     *
     * @param matcher The matcher validating the actual commands
     */
    public void assertDispatchedMatching(Matcher<?> matcher) {
        if (!matcher.matches(commandBus.getDispatchedCommands())) {
            Description expectedDescription = new StringDescription();
            Description actualDescription = new StringDescription();
            matcher.describeTo(expectedDescription);
            describe(commandBus.getDispatchedCommands(), actualDescription);
            throw new AxonAssertionError(format("Incorrect dispatched command. Expected <%s>, but got <%s>",
                                                expectedDescription, actualDescription));
        }
View Full Code Here

     *
     * @param matcher The matcher that will validate the actual events
     */
    public void assertPublishedEventsMatching(Matcher<? extends Iterable<?>> matcher) {
        if (!matcher.matches(publishedEvents)) {
            StringDescription expectedDescription = new StringDescription();
            StringDescription actualDescription = new StringDescription();
            matcher.describeTo(expectedDescription);
            describe(publishedEvents, actualDescription);
            throw new AxonAssertionError(format("Published events did not match.\nExpected:\n<%s>\n\nGot:\n<%s>\n",
                                                expectedDescription, actualDescription));
        }
View Full Code Here

        assertThat("", actual, matcher);
    }
   
    public static <T> void assertThat(String reason, T actual, Matcher<T> matcher) {
        if (!matcher.matches(actual)) {
            Description description = new StringDescription();
            description.appendText(reason);
            description.appendText("\nExpected: ");
            matcher.describeTo(description);
            description.appendText("\n     got: ").appendValue(actual).appendText("\n");
            throw new java.lang.AssertionError(description.toString());
        }
    }
View Full Code Here

    public void should_display_expected_xml_document_when_failing() {

        String anXmlDocument = "<sale><item code='a'>Item A</item></sale>";

        XMLIsSimilarMatcher matcher = new XMLIsSimilarMatcher(anXmlDocument);
        Description description = new StringDescription();
        matcher.describeTo(description);

        assertThat(description.toString(), is("an XML document equivalent to <sale><item code='a'>Item A</item></sale>"));
    }
View Full Code Here

        String anXmlDocument = "<sale><item code='a'>Item A</item></sale>";
        String aDifferentXmlDocument = "<loan><item code='a'>Item A</item></loan>";

        XMLIsSimilarMatcher matcher = new XMLIsSimilarMatcher(anXmlDocument);
        matcher.matchesSafely(aDifferentXmlDocument);
        Description description = new StringDescription();
        matcher.describeTo(description);

        assertThat(description.toString(), containsString("an XML document equivalent to <sale><item code='a'>Item A</item></sale>"));
        assertThat(description.toString(), containsString("[different]"));

    }
View Full Code Here

    private final String msg;

    @Override
    public void is(Matcher<? super T> matching) {
        Description message = new StringDescription();
        message.appendText("expecting ");
        matching.describeTo(message);
        message.appendText(" but ");
        T obj = provider.get();
        if (!matching.matches(obj)) {
            matching.describeMismatch(obj, message);
            if (assertion) {
                throw new AssertionError((msg == null ? "" : msg + "\n")
                        + message.toString());
            } else {
                throw new AssumptionError((msg == null ? "" : msg + "\n")
                        + message.toString());
            }
        }
    }
View Full Code Here

TOP

Related Classes of org.hamcrest.StringDescription

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.