Package org.hamcrest

Examples of org.hamcrest.Description


            this.description = description;
        }

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            Description descriptionParameter = (Description) invocation.getArguments()[0];
            descriptionParameter.appendText(this.description);
            return Void.class;
        }
View Full Code Here


     * Assert that the condition is satisfied.
     * @throws AssertionError if the condition is not satisfied
     */
    public static void assertThat(Condition condition) {
        if(condition.isSatisfied()) return;
        Description description = new StringDescription();
        description.appendText("\nExpected: ")
                    .appendDescriptionOf(condition)
                    .appendText("\n     but: ");
        condition.describeDissatisfactionTo(description);
        throw new AssertionError(description.toString());
    }
View Full Code Here

   
    return allSatisfied;
  }
 
  private boolean isExpectationSatisfied(Expectation expectation, Description description) {
    Description subDescription = new StringDescription();
    boolean isSatisfied = expectation.isSatisfied(subDescription);
    if (!isSatisfied) {
      description.appendValue(subDescription).appendText("\n");
    }
    return isSatisfied;
View Full Code Here

  }

 
  private void assertServers(List<FakeServer> servers) {
    StringBuilder failMessage = new StringBuilder();
    Description mismatchDescription = new StringDescription(failMessage);
    boolean allSatisfied = true;
   
    for (FakeServer server : servers) {
      boolean isSatisfied = server.isSatisfied(mismatchDescription);
      allSatisfied &= isSatisfied;
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

    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(i18n(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

@SuppressWarnings("unchecked")
public class MatchersPrinter {
   
    public String getArgumentsLine(List<Matcher> matchers, PrintSettings printSettings) {
        Description result = new StringDescription();
        result.appendList("(", ", ", ");", applyPrintSettings(matchers, printSettings));
        return result.toString();
    }
View Full Code Here

        result.appendList("(", ", ", ");", applyPrintSettings(matchers, printSettings));
        return result.toString();
    }

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

    public static void assertThat(Condition condition) {
        if(!condition.isSatisfied()) fail(condition);
    }

    private static void fail(Condition condition) {
        Description description = new StringDescription();
        description.appendText("Expected: ");
        condition.describeTo(description);
        description.appendText("\n  but: ");
        condition.describeDissatisfactionTo(description);
        throw new AssertionError(description.toString());
    }
View Full Code Here

    public PollTimeoutException(Condition condition) {
        super(explainTimeoutOf(condition));
    }

    private static String explainTimeoutOf(Condition condition) {
        Description description = new StringDescription();
        description.appendText("Timed out waiting until ");
        condition.describeTo(description);
        description.appendText("\n   because ");
        condition.describeDissatisfactionTo(description);
        return 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.