01: package org.junit.matchers;
02:
03: import org.hamcrest.Description;
04:
05: public abstract class SubstringMatcher extends TypeSafeMatcher<String> {
06:
07: protected final String substring;
08:
09: protected SubstringMatcher(final String substring) {
10: this .substring = substring;
11: }
12:
13: @Override
14: public boolean matchesSafely(String item) {
15: return evalSubstringOf(item);
16: }
17:
18: public void describeTo(Description description) {
19: description.appendText("a string ").appendText(relationship())
20: .appendText(" ").appendValue(substring);
21: }
22:
23: protected abstract boolean evalSubstringOf(String string);
24:
25: protected abstract String relationship();
26: }
|