HasToString extends FeatureMatcher<T, String> { public HasToString(Matcher<? super String> toStringMatcher) { super(toStringMatcher, "with toString()", "toString()"); } HasToString(Matcher<? super String> toStringMatcher); static Matcher<T> hasToString(Matcher<? super String> toStringMatcher); static Matcher<T> hasToString(String expectedToString);  }
@Test public void copesWithNullsAndUnknownTypes() { Matcher<Object> matcher = hasToString(equalTo("irrelevant")); assertNullSafe(matcher); assertUnknownTypeSafe(matcher); }
@Test public void matchesWhenUtilisingANestedMatcher() { final Matcher<Object> matcher = hasToString(equalTo(TO_STRING_RESULT)); assertMatches(matcher, TEST_OBJECT); assertDoesNotMatch(matcher, new Object()); }
@Test public void matchesWhenUsingShortcutForHasToStringEqualTo() { final Matcher<Object> matcher = hasToString(TO_STRING_RESULT); assertMatches(matcher, TEST_OBJECT); assertDoesNotMatch(matcher, new Object()); }
@Test public void describesItself() { final Matcher<Object> matcher = hasToString(equalTo(TO_STRING_RESULT)); assertDescription("with toString() \"toString result\"", matcher); }
@Test public void describesAMismatch() { final Matcher<Object> matcher = hasToString(equalTo(TO_STRING_RESULT)); String expectedMismatchString = "toString() was \"Cheese\""; assertMismatchDescription(expectedMismatchString, matcher, "Cheese"); }