Package org.hamcrest

Examples of org.hamcrest.Description


    /**
     * The reason the condition was dissatisfied.
     */
    public String reason() {
        Description description = new StringDescription();
        condition.describeDissatisfactionTo(description);
        return description.toString();
    }
View Full Code Here


    public <T> boolean that(T actual, Matcher<? super T> matcher, String category, String reason, Object... messageParameters) {
        if (!matcher.matches(actual)) {
            if (reason != null) {
                errors.add(new ValidationMessage(getString(reason), category, messageParameters));
            } else {
                Description description = new ResourceBundleDescription(bundle);
                description.appendDescriptionOf(matcher);
                errors.add(new ValidationMessage(description.toString(), category));
            }
            return false;
        }
        return true;
    }
View Full Code Here

  public void testMatchesPropertyAndValue() {
    assertMatches("property with value", hasProperty( "property", anything()), beanWithInfo);
  }
 
  public void testDoesNotWriteMismatchIfPropertyMatches() {
    Description description = new StringDescription();
    hasProperty( "property", anything()).describeMismatch(beanWithInfo, description);
    assertEquals("Expected mismatch description", "", description.toString());
  }
View Full Code Here

        String listenersText = text.replaceAll("time=-?\\d+", "time=SOME_TIME_AGO").replaceAll("x=\\d+", "x=X_CO_ORDINATE").replaceAll("y=\\d+", "y=Y_CO_ORDINATE").replaceAll("keyLocation=\\d+ ", "");
        return matcher.matches(listenersText);
      }

      public String getFailureMessage() {
        Description description = new StringDescription();
        description.appendText("\nExpected:\n").appendDescriptionOf(matcher).appendText("\ngot:\n").appendValue(text).appendText("\n");
        return description.toString();
      }
    });
  }
View Full Code Here

  private <T> boolean genericThat(T actual, Matcher<? super T> matcher, Object category, String reason, Object... messageParameters) {
    if (!matcher.matches(actual)) {
          if (reason != null) {
            errors.add(i18nMessage(category, reason, messageParameters));
            } else {
                Description description = new ResourceBundleDescription();
                description.appendDescriptionOf(matcher);
                errors.add(i18nMessage(category, description.toString(), actual));
            }
            return false;
        }
        return true;
  }
View Full Code Here

        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

        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

TOP

Related Classes of org.hamcrest.Description

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.