Package org.hamcrest

Examples of org.hamcrest.Description


    }
   
    @Test
    public void matcherShouldDescribeMismatchCorrectlyIfResponseHasNoHeaders() {
        Response mockResponse = mock(Response.class);
        Description description = new StringDescription();
        matcher.describeMismatchSafely(mockResponse, description);
       
        assertThat(description.toString(), is("Response has no headers"));
    }
View Full Code Here


   
    @Test
    public void matcherShouldDescribeMismatchCorrectlyIfResponseHasHeaders() {
        Response mockResponse = mock(Response.class);
        when(mockResponse.getHeaders()).thenReturn(Arrays.asList(new Header("Header1: value"), new Header("Header2: value")));
        Description description = new StringDescription();
        matcher.describeMismatchSafely(mockResponse, description);
       
        assertThat(description.toString(), is("Response has headers [Header1: value, Header2: value]"));
    }
View Full Code Here

            }

            @Override
            public String toString() {
                Description description = new StringDescription();
                description.appendText("HasDeclaredAnnotation(").appendText(annotationName);
                defaultValueMatcher.describeTo(description);
                description.appendText(")");
                return description.toString();
            }

            @Override
            public void describeTo(Description description) {
                description.appendText(toString());
            }
        };
    }
View Full Code Here

            }

            @Override
            public String toString() {
                Description description = new StringDescription();
                description.appendText("HasDeclaredAnnotation(").appendText(annotationName);
                description.appendText(")");
                return description.toString();
            }

            @Override
            public void describeTo(Description description) {
                description.appendText(toString());
            }
        };
    }
View Full Code Here

        this.condition = condition;
    }

    @Override
    public Void call() throws RuntimeException {
        Description description = new StringDescription();
        condition.describeTo(description);
        throw new AssertionError(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

    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 I18nMessage(category, reason, messageParameters));
            } else {
                Description description = new ResourceBundleDescription();
                description.appendDescriptionOf(matcher);
                errors.add(new I18nMessage(description.toString(), category));
            }
            return false;
        }
        return true;
    }
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: ");
      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

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.