22 */
33package org .hamcrest ;
44
5- import junit .framework .AssertionFailedError ;
5+ import static org .hamcrest .core .Always .alwaysPasses ;
6+ import static org .hamcrest .core .Always .alwaysFails ;
67import junit .framework .TestCase ;
7- import org .hamcrest .core .Always ;
88
99public abstract class AbstractMatcherTest extends TestCase {
10- protected static final Matcher TRUE_MATCHER = new Always (true );
11- protected static final Matcher FALSE_MATCHER = new Always (false );
1210
13- protected static final Matcher NEVER_EVALUATED = new Matcher () {
14- public boolean matches (Object o ) {
15- throw new AssertionFailedError ("matcher should not have been evaluated" );
16- }
11+ protected static final Matcher <Boolean > TRUE_MATCHER = alwaysPasses ();
12+ protected static final Matcher <Boolean > FALSE_MATCHER = alwaysFails ();
1713
18- public void describeTo ( Description description ) {
19- description . appendText ( "NEVER_EVALUATED" );
20- }
21- } ;
14+ /**
15+ * Create an instance of the Matcher so some generic safety-net tests can be run on it.
16+ */
17+ protected abstract Matcher <?> createMatcher () ;
2218
2319 protected static final Object ARGUMENT_IGNORED = new Object ();
2420 protected static final Object ANY_NON_NULL_ARGUMENT = new Object ();
@@ -36,4 +32,10 @@ public void assertDescription(String expected, Matcher matcher) {
3632 matcher .describeTo (description );
3733 assertEquals (expected , description .toString ());
3834 }
35+
36+ public void testIsNullSafe () {
37+ // should not throw a NullPointerException
38+ createMatcher ().matches (null );
39+ }
40+
3941}
0 commit comments