@Factory public static StringStartsWith startsWithStripNewLines(final String expected) { final String strippedExpected = StringUtils.stripNewLines(expected); return new StringStartsWith(strippedExpected) { @Override public boolean matchesSafely(final String actual) { return super.matchesSafely(StringUtils.stripNewLines(actual)); } @Override public void describeTo(final Description description) { description .appendText("a string (ignoring new lines) starting with") .appendValue(strippedExpected); } }; }
@Factory public static Matcher<String> containsStripNewLines(final String expected) { final String strippedExpected = StringUtils.stripNewLines(expected); return new StringContains(strippedExpected) { @Override public boolean matchesSafely(final String actual) { return super.matchesSafely(StringUtils.stripNewLines(actual)); } @Override public void describeTo(final Description description) { description .appendText("a string (ignoring new lines) containing") .appendValue(strippedExpected); } }; }
@Factory public static Matcher<String> equalToStripNewLines(final String expected) { final String strippedExpected = StringUtils.stripNewLines(expected); return new IsEqual<String>(strippedExpected) { @Override public boolean matches(final Object actualObj) { final String actual = (String) actualObj; return super.matches(StringUtils.stripNewLines(actual)); } @Override public void describeTo(final Description description) { description .appendText("a string (ignoring new lines) equal to") .appendValue(strippedExpected); } }; }