|
2 | 2 | */ |
3 | 3 | package org.hamcrest.core; |
4 | 4 |
|
5 | | -import static org.hamcrest.MatcherAssert.assertThat; |
6 | | -import static org.hamcrest.core.IsNot.not; |
| 5 | +import static org.hamcrest.AbstractMatcherTest.assertDoesNotMatch; |
| 6 | +import static org.hamcrest.AbstractMatcherTest.assertMatches; |
| 7 | +import static org.hamcrest.AbstractMatcherTest.assertNullSafe; |
| 8 | +import static org.hamcrest.AbstractMatcherTest.assertUnknownTypeSafe; |
7 | 9 | import static org.hamcrest.core.IsNull.notNullValue; |
8 | 10 | import static org.hamcrest.core.IsNull.nullValue; |
9 | 11 |
|
10 | | -import java.math.BigDecimal; |
11 | | - |
12 | | -import org.hamcrest.AbstractMatcherTest; |
13 | 12 | import org.hamcrest.Matcher; |
| 13 | +import org.junit.Test; |
14 | 14 |
|
15 | 15 |
|
16 | | -public class IsNullTest extends AbstractMatcherTest { |
17 | | - private static final BigDecimal ANY_NON_NULL_ARGUMENT = new BigDecimal(66); |
18 | | - |
19 | | - @Override |
20 | | - protected Matcher<?> createMatcher() { |
21 | | - return nullValue(); |
22 | | - } |
| 16 | +public final class IsNullTest { |
23 | 17 |
|
24 | | - public void testEvaluatesToTrueIfArgumentIsNull() { |
25 | | - assertThat(null, nullValue()); |
26 | | - assertThat(ANY_NON_NULL_ARGUMENT, not(nullValue())); |
| 18 | + private final Matcher<Object> nullMatcher = nullValue(); |
| 19 | + private final Matcher<Object> notNullMatcher = notNullValue(); |
27 | 20 |
|
28 | | - assertThat(ANY_NON_NULL_ARGUMENT, notNullValue()); |
29 | | - assertThat(null, not(notNullValue())); |
| 21 | + @Test public void |
| 22 | + copesWithNullsAndUnknownTypes() { |
| 23 | + assertNullSafe(nullMatcher); |
| 24 | + assertUnknownTypeSafe(nullMatcher); |
| 25 | + |
| 26 | + assertNullSafe(notNullMatcher); |
| 27 | + assertUnknownTypeSafe(notNullMatcher); |
30 | 28 | } |
31 | 29 |
|
32 | | - public void testSupportsStaticTyping() { |
| 30 | + @Test public void |
| 31 | + evaluatesToTrueIfArgumentIsNull() { |
| 32 | + assertMatches("didn't match", nullMatcher, null); |
| 33 | + assertDoesNotMatch("matched unexpectedly", nullMatcher, new Object()); |
| 34 | + |
| 35 | + assertMatches("didn't match", notNullMatcher, new Object()); |
| 36 | + assertDoesNotMatch("matched unexpectedly", notNullMatcher, null); |
| 37 | + } |
| 38 | + |
| 39 | + @Test public void |
| 40 | + supportsStaticTyping() { |
33 | 41 | requiresStringMatcher(nullValue(String.class)); |
34 | 42 | requiresStringMatcher(notNullValue(String.class)); |
35 | 43 | } |
36 | 44 |
|
37 | 45 | private void requiresStringMatcher(@SuppressWarnings("unused") Matcher<String> arg) { |
38 | 46 | // no-op |
39 | | - } |
| 47 | + } |
40 | 48 | } |
0 commit comments