Java Code Examples for org.hamcrest.StringDescription.toString()

The following are Jave code examples for showing how to use toString() of the org.hamcrest.StringDescription class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: mario   File: PollingProber.java   Source Code and License Vote up 5 votes
private static String failureDescriptionOf(Probe probe) {
    final StringDescription description = new StringDescription();

    description.appendText("\nTried to:\n    ")
               .appendDescriptionOf(probe)
               .appendText("\nbut:\n    ");
    probe.describeFailureTo(description);

    return description.toString();
}
 
Example 2
Project: FSDevTools   File: ServerProperties.java   Source Code and License Vote up 5 votes
private static <T> void assertThat(final T obj, final String name, final Matcher<T> matcher) {
    if (!matcher.matches(obj)) {
        final StringDescription description = new StringDescription();
        description.appendText(name).appendText(" must fulfill this spec: ").appendDescriptionOf(matcher).appendText("\nbut: ");
        matcher.describeMismatch(obj, description);
        throw new IllegalArgumentException(description.toString());
    }
}
 
Example 3
Project: AxoloTL   File: DescriptionBuilder.java   Source Code and License Vote up 4 votes
public static String exceptionClassErrorStr(Class expected, Class actual) {
    StringDescription sd = new StringDescription();
    exceptionClassError(sd, expected, actual);
    return sd.toString();
}
 
Example 4
Project: AxoloTL   File: DescriptionBuilder.java   Source Code and License Vote up 4 votes
public static String errorCodeMismatchStr(int expectedErrorCode, int actualErrorCode) {
    StringDescription sd = new StringDescription();
    errorCodeMismatch(sd, expectedErrorCode, actualErrorCode);
    return sd.toString();
}
 
Example 5
Project: AxoloTL   File: DescriptionBuilder.java   Source Code and License Vote up 4 votes
public static String errorObjectMismatchStr(Object expectedErrorObject, Object actualErrorObject) {
    StringDescription sd = new StringDescription();
    errorObjectMismatch(sd, expectedErrorObject, actualErrorObject);
    return sd.toString();
}
 
Example 6
Project: beam   File: ApiSurface.java   Source Code and License Vote up 4 votes
private boolean verifyNoAbandoned(
    final ApiSurface checkedApiSurface,
    final Set<Matcher<Class<?>>> allowedClasses,
    final Description mismatchDescription) {

  // <helper_lambdas>

  final Function<Matcher<Class<?>>, String> toMessage =
      new Function<Matcher<Class<?>>, String>() {

        @Override
        public String apply(@Nonnull final Matcher<Class<?>> abandonedClassMacther) {
          final StringDescription description = new StringDescription();
          description.appendText("No ");
          abandonedClassMacther.describeTo(description);
          return description.toString();
        }
      };

  final Predicate<Matcher<Class<?>>> matchedByExposedClasses =
      new Predicate<Matcher<Class<?>>>() {

        @Override
        public boolean apply(@Nonnull final Matcher<Class<?>> classMatcher) {
          return FluentIterable.from(checkedApiSurface.getExposedClasses())
              .anyMatch(
                  new Predicate<Class<?>>() {

                    @Override
                    public boolean apply(@Nonnull final Class<?> aClass) {
                      return classMatcher.matches(aClass);
                    }
                  });
        }
      };

  // </helper_lambdas>

  final ImmutableSet<Matcher<Class<?>>> matchedClassMatchers =
      FluentIterable.from(allowedClasses).filter(matchedByExposedClasses).toSet();

  final Sets.SetView<Matcher<Class<?>>> abandonedClassMatchers =
      Sets.difference(allowedClasses, matchedClassMatchers);

  final ImmutableList<String> messages =
      FluentIterable.from(abandonedClassMatchers)
          .transform(toMessage)
          .toSortedList(Ordering.<String>natural());

  if (!messages.isEmpty()) {
    mismatchDescription.appendText(
        "The following white-listed scopes did not have matching classes on the API surface:"
            + "\n\t"
            + Joiner.on("\n\t").join(messages));
  }

  return messages.isEmpty();
}