diff options
Diffstat (limited to 'hamcrest-core/src/test/java/org/hamcrest/CustomTypeSafeMatcherTest.java')
-rw-r--r-- | hamcrest-core/src/test/java/org/hamcrest/CustomTypeSafeMatcherTest.java | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/hamcrest-core/src/test/java/org/hamcrest/CustomTypeSafeMatcherTest.java b/hamcrest-core/src/test/java/org/hamcrest/CustomTypeSafeMatcherTest.java new file mode 100644 index 0000000..2c86712 --- /dev/null +++ b/hamcrest-core/src/test/java/org/hamcrest/CustomTypeSafeMatcherTest.java @@ -0,0 +1,41 @@ +package org.hamcrest; + +import org.junit.Test; + +import static org.hamcrest.AbstractMatcherTest.*; + +public final class CustomTypeSafeMatcherTest { + private static final String STATIC_DESCRIPTION = "I match non empty strings"; + + private final Matcher<String> customMatcher = new CustomTypeSafeMatcher<String>(STATIC_DESCRIPTION) { + @Override + public boolean matchesSafely(String item) { + return false; + } + + @Override + public void describeMismatchSafely(String item, Description mismatchDescription) { + mismatchDescription.appendText("an " + item); + } + }; + + @Test public void + usesStaticDescription() throws Exception { + assertDescription(STATIC_DESCRIPTION, customMatcher); + } + + @Test public void + reportsMismatch() { + assertMismatchDescription("an item", customMatcher, "item"); + } + + @Test public void + isNullSafe() { + assertNullSafe(customMatcher); + } + + @Test public void + copesWithUnknownTypes() { + assertUnknownTypeSafe(customMatcher); + } +} |