@Override public void describeTo(Description description) { description.appendText("a Complex number having "); reMatcher.describeTo(description); description.appendText(" as real part and "); imMatcher.describeTo(description); description.appendText(" as imaginary part"); }
@Test public void shouldBeDescriptive() { Matcher<Object> matcher = isJson(withPathEvaluatedTo(true)); Description description = new StringDescription(); matcher.describeTo(description); assertThat(description.toString(), startsWith("is json")); assertThat(description.toString(), containsString(TestingMatchers.MATCH_TRUE_TEXT)); }
@Test public void assertThatSmallGraphIsDescribable() { Graph graph1 = makeSmallGraph("A"); Matcher<? super Graph> matcher = deeplyEqualTo(graph1); StringDescription description = new StringDescription(); matcher.describeTo(description); assertThat( description.toString(), allOf( startsWith("{" + System.getProperty("line.separator") + " nodes ["), containsString("value is <"), containsString("neighbors ["), containsString("&Node<A-1>"))); }
final String createErrorMessage(final Throwable thrown) { final StringBuilder msg = new StringBuilder(128); if (hasNullMessage(thrown)) msg.append(beforeNullActual); else msg.append(beforeActual).append(getActualMessage(thrown)).append(afterActual); msg.append(beforeExpected); final Matcher expectedMatcher = getExpectedMatcher(); if (expectedMatcher != null) { final int insertAt = msg.length(); final String shouldStartWith = expectedMatcherPrefix; final boolean[] startsThat = {false}; expectedMatcher.describeTo( new BaseDescription() { private int i, upTo = shouldStartWith.length(); @Override protected void append(char c) { if (i < upTo && (i == 0 || startsThat[0])) startsThat[0] = c == shouldStartWith.charAt(i); ++i; msg.append(c); } @Override public String toString() { return msg.toString(); } }); if (!startsThat[0]) msg.insert(insertAt, shouldStartWith); } else msg.append(getExpectedMessage()); msg.append(afterExpected); return msg.toString(); }
@Override public void describeTo(Description description) { directoryMatcher.describeTo(description); description.appendText(" containing ").appendDescriptionOf(this.fileMatcher); }
@Override public void describeTo(Description description) { containsAll.describeTo(description); }
@Override public void describeTo(Description description) { description.appendText("name "); nameMatcher.describeTo(description); }
@Override public void describeTo(Description description) { description.appendText(memberDescription); matcher.describeTo(description); }
@Override public void describeTo(Description description) { description.appendText("A JSON array with value at " + position + " which matches: "); matcher.describeTo(description); }