public String toString() { //TODO SF add unit tests and integ test coverage for describeTo() return StringDescription.toString(matcher); } }
/** * Alias for {@link #toString(SelfDescribing)}. */ public static String asString(SelfDescribing selfDescribing) { return toString(selfDescribing); }
@Override public String toString() { return StringDescription.toString(this); } }
@Override public String toString() { return StringDescription.toString(this); } }
/** * Alias for {@link #toString(SelfDescribing)}. */ public static String asString(SelfDescribing selfDescribing) { return toString(selfDescribing); }
/** * Alias for {@link #toString(SelfDescribing)}. */ public static String asString(SelfDescribing selfDescribing) { return toString(selfDescribing); }
@Override public String toString() { return StringDescription.toString(this); }
private boolean toStringEquals(Matcher m, Object arg) { return StringDescription.toString(m).equals(arg == null? "null" : arg.toString()); } }
private String missingExceptionMessage() { String expectation= StringDescription.toString(matcherBuilder.build()); return format(missingExceptionMessage, expectation); } }
private void failDueToMissingException() throws AssertionError { String expectation = StringDescription.toString(fMatcherBuilder.build()); fail("Expected test to throw " + expectation); }
@Override protected boolean matchesSafely(Matcher m, Description mismatchDescription) { StringDescription stringDescription = new StringDescription(); m.describeTo(stringDescription); final String description = stringDescription.toString(); if (!matcher.matches(description)) { mismatchDescription.appendText("description "); matcher.describeMismatch(description, mismatchDescription); return false; } return true; }
public String buildError(T actual, M matcher) { final StringDescription descriptionBuilder = new StringDescription(); descriptionBuilder.appendText("Expected ").appendText(name).appendText(" "); matcher.describeTo(descriptionBuilder); descriptionBuilder.appendText(" but "); matcher.describeMismatch(actual, descriptionBuilder); final String description = descriptionBuilder.toString().replaceAll("[.\\n]+$", ""); return description + ".\n"; } }
public void testHasReadableDescription() { Matcher<String> isIn = new IsIn<String>(elements); assertEquals("description", "one of {\"a\", \"b\", \"c\"}", StringDescription.toString(isIn)); } }
public void assertContainsMessageMatching( Matcher<String> messageMatcher ) { synchronized ( logCalls ) { for ( LogCall logCall : logCalls ) { if ( messageMatcher.matches( logCall.message ) ) { return; } } StringDescription description = new StringDescription(); description.appendDescriptionOf( messageMatcher ); fail( format( "Expected at least one log statement with message as %s, but none found. Actual log calls were:\n%s", description.toString(), serialize( logCalls.iterator() ) ) ); } }
@SafeVarargs public final void assertContainsLogCallsMatching( int logSkipCount, Matcher<String>... matchers ) { synchronized ( logCalls ) { assertEquals( logCalls.size(), logSkipCount + matchers.length ); for ( int i = 0; i < matchers.length; i++ ) { LogCall logCall = logCalls.get( logSkipCount + i ); Matcher<String> matcher = matchers[i]; if ( !matcher.matches( logCall.message ) ) { StringDescription description = new StringDescription(); description.appendDescriptionOf( matcher ); fail( format( "Expected log statement with message as %s, but none found. Actual log call was:\n%s", description.toString(), logCall.toString() ) ); } } } }
@Test public void testContainsCharSequence() { final Matcher<CharSequence> angeryMatcher = containsCharSequence("angery"); assertThat(angeryMatcher.matches("angery reaccs only")).isTrue(); assertThat(angeryMatcher.matches("delet dis")).isFalse(); final StringDescription description = new StringDescription(); angeryMatcher.describeMismatch("delet", description); assertThat(description.toString()).isEqualTo("was \"delet\""); } }
@Test public void testIsEmpty() { assertThat(LongStream.empty(), isEmpty()); StringDescription description = new StringDescription(); isEmpty().describeTo(description); assertThat(description.toString(), is("an empty stream")); }
@Test public void testIsEmpty() { assertThat(Stream.empty(), isEmpty()); StringDescription description = new StringDescription(); isEmpty().describeTo(description); assertThat(description.toString(), is("an empty stream")); }
@Test public void testHasElements() { assertThat(IntStream.of(1, 2), hasElements()); assertThat(IntStream.empty(), not(hasElements())); StringDescription description = new StringDescription(); hasElements().describeTo(description); assertThat(description.toString(), is("a non-empty stream")); }
@Test public void doesNotThrowClassCastException() { resultMatcher.matches(new ShouldNotMatch()); StringDescription mismatchDescription = new StringDescription(); resultMatcher.describeMismatch(new ShouldNotMatch(), mismatchDescription); assertEquals("was ShouldNotMatch <ShouldNotMatch>", mismatchDescription.toString()); }