Package org.hamcrest

Examples of org.hamcrest.StringDescription


   * @see org.junit.matchers.JUnitMatchers
   */
  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: ");
      description.appendDescriptionOf(matcher);
      description.appendText("\n     got: ");
      description.appendValue(actual);
      description.appendText("\n");
      throw new java.lang.AssertionError(description.toString());
    }
  }
View Full Code Here


   * @see org.junit.matchers.JUnitMatchers
   */
  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

    // Feels very esoteric and not for typical usage used to override the
    // description
    @Test
    public void describedAsExample() throws Exception {
        Matcher<?> matcher = describedAs("My Description", anything());
        Description description = new StringDescription().appendDescriptionOf(matcher);
        assertThat("My Description", is(description.toString()));
    }
View Full Code Here

                        new NoEqualsDummy(Arrays.asList(null, null))),
                containsString("\"this.obj.size()\""));
    }

    private static String getMismatchDescription(Object actual, Object expected) {
        StringDescription description = new StringDescription();
        deepEqualTo(expected).describeMismatch(actual, description);
        return description.toString();
    }
View Full Code Here

    private String getMatchMessage(Callable<T> supplier, Matcher<? super T> matcher) {
        return String.format("%s reached its end value of %s", getCallableDescription(supplier), HamcrestToStringFilter.filter(matcher));
    }

    private String getMismatchMessage(Callable<T> supplier, Matcher<? super T> matcher) {
        Description mismatchDescription = new StringDescription();
        matcher.describeMismatch(lastResult, mismatchDescription);
        return String.format("%s expected %s but %s", getCallableDescription(supplier), HamcrestToStringFilter.filter(matcher), mismatchDescription);
    }
View Full Code Here

   *
   * @throws IllegalStateException if the check fails.
   */
  public static <T> void that(T actual, Matcher<T> matcher, String message) {
    if (!matcher.matches(actual)) {
      Description description = new StringDescription();
      if (message != null && message.length() > 0) {
        description.appendText(message).appendText(" - ");
      }
      description.appendValue(actual).appendText(" must be ");
      matcher.describeTo(description);
      throw new IllegalStateException(matcher.toString());
    }
  }
View Full Code Here

    private String qualifiedMethodName() {
        return MockUtil.getMockName(mock) + "." + method.getName();
    }

    private String getArgumentsLine(List<Matcher> matchers) {
        Description result = new StringDescription();
        result.appendList("(", ", ", ");", matchers);
        return result.toString();
    }
View Full Code Here

        result.appendList("(", ", ", ");", matchers);
        return result.toString();
    }
   
    private String getArgumentsBlock(List<Matcher> matchers) {
        Description result = new StringDescription();
        result.appendList("(\n    ", ",\n    ", "\n);", matchers);
        return result.toString();
    }
View Full Code Here

   * @param actual the value to match against
   * @param matcher the 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: ");
      description.appendDescriptionOf(matcher);
      if (describeMismatchMethod != null) {
        description.appendText("\n     but: ");
        // matcher.describeMismatch(actual, description);
        ReflectionUtils.invokeMethod(describeMismatchMethod, matcher, actual, description);
      }
      else {
        description.appendText("\n     got: ");
        description.appendValue(actual);
        description.appendText("\n");
      }
      throw new AssertionError(description.toString());
    }
  }
View Full Code Here

    @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());
    }
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.