|
1 | 1 | package org.hamcrest.core; |
2 | 2 |
|
3 | | -import static org.hamcrest.core.IsEqual.equalTo; |
| 3 | +import static junit.framework.TestCase.assertFalse; |
| 4 | +import static junit.framework.TestCase.assertTrue; |
| 5 | +import static org.hamcrest.AbstractMatcherTest.assertDescription; |
| 6 | +import static org.hamcrest.AbstractMatcherTest.assertDoesNotMatch; |
| 7 | +import static org.hamcrest.AbstractMatcherTest.assertMatches; |
| 8 | +import static org.hamcrest.AbstractMatcherTest.assertNullSafe; |
| 9 | +import static org.hamcrest.AbstractMatcherTest.assertUnknownTypeSafe; |
4 | 10 | import static org.hamcrest.core.Is.is; |
5 | 11 | import static org.hamcrest.core.Is.isA; |
6 | | -import org.hamcrest.AbstractMatcherTest; |
| 12 | +import static org.hamcrest.core.IsEqual.equalTo; |
| 13 | + |
7 | 14 | import org.hamcrest.Matcher; |
| 15 | +import org.junit.Test; |
8 | 16 |
|
9 | | -public class IsTest extends AbstractMatcherTest { |
| 17 | +public final class IsTest { |
10 | 18 |
|
11 | | - @Override |
12 | | - protected Matcher<?> createMatcher() { |
13 | | - return is("something"); |
| 19 | + @Test public void |
| 20 | + copesWithNullsAndUnknownTypes() { |
| 21 | + Matcher<String> matcher = is("something"); |
| 22 | + |
| 23 | + assertNullSafe(matcher); |
| 24 | + assertUnknownTypeSafe(matcher); |
14 | 25 | } |
15 | 26 |
|
16 | | - public void testJustMatchesTheSameWayTheUnderlyingMatcherDoes() { |
17 | | - assertMatches("should match", is(equalTo(true)), true); |
18 | | - assertMatches("should match", is(equalTo(false)), false); |
19 | | - assertDoesNotMatch("should not match", is(equalTo(true)), false); |
20 | | - assertDoesNotMatch("should not match", is(equalTo(false)), true); |
| 27 | + @Test public void |
| 28 | + matchesTheSameWayTheUnderlyingMatcherDoes() { |
| 29 | + final Matcher<Boolean> matcher = is(equalTo(true)); |
| 30 | + |
| 31 | + assertMatches("didn't match", matcher, true); |
| 32 | + assertDoesNotMatch("matched unexpectedly", matcher, false); |
21 | 33 | } |
22 | 34 |
|
23 | | - public void testGeneratesIsPrefixInDescription() { |
| 35 | + @Test public void |
| 36 | + generatesIsPrefixInDescription() { |
24 | 37 | assertDescription("is <true>", is(equalTo(true))); |
| 38 | + assertDescription("is \"A\"", is("A")); |
25 | 39 | } |
26 | 40 |
|
27 | | - public void testProvidesConvenientShortcutForIsEqualTo() { |
28 | | - assertMatches("should match", is("A"), "A"); |
29 | | - assertMatches("should match", is("B"), "B"); |
30 | | - assertDoesNotMatch("should not match", is("A"), "B"); |
31 | | - assertDoesNotMatch("should not match", is("B"), "A"); |
32 | | - assertDescription("is \"A\"", is("A")); |
| 41 | + @Test public void |
| 42 | + providesConvenientShortcutForIsEqualTo() { |
| 43 | + final Matcher<String> matcher = is("A"); |
| 44 | + |
| 45 | + assertMatches("didn't match", matcher, "A"); |
| 46 | + assertDoesNotMatch("matched unexpectedly", is("A"), "B"); |
33 | 47 | } |
34 | 48 |
|
35 | | - public void testProvidesConvenientShortcutForIsInstanceOf() { |
36 | | - assertTrue("should match", isA(String.class).matches("A")); |
37 | | - assertFalse("should not match", isA(Integer.class).matches(new Object())); |
38 | | - assertFalse("should not match", isA(Integer.class).matches(null)); |
| 49 | + @SuppressWarnings({ "unchecked", "rawtypes" }) |
| 50 | + @Test public void |
| 51 | + providesConvenientShortcutForIsInstanceOf() { |
| 52 | + final Matcher matcher = isA(Integer.class); |
| 53 | + assertMatches("didn't match", matcher, Integer.valueOf(1)); |
| 54 | + assertDoesNotMatch("matched unexpectedly", matcher, new Object()); |
| 55 | + assertDoesNotMatch("matched unexpectedly", matcher, null); |
39 | 56 | } |
40 | 57 | } |
0 commit comments