Skip to content

Commit d38bfcc

Browse files
committed
convert to JUnit 4
1 parent c5050d1 commit d38bfcc

1 file changed

Lines changed: 39 additions & 22 deletions

File tree

  • hamcrest-core/src/test/java/org/hamcrest/core
Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,57 @@
11
package org.hamcrest.core;
22

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;
410
import static org.hamcrest.core.Is.is;
511
import static org.hamcrest.core.Is.isA;
6-
import org.hamcrest.AbstractMatcherTest;
12+
import static org.hamcrest.core.IsEqual.equalTo;
13+
714
import org.hamcrest.Matcher;
15+
import org.junit.Test;
816

9-
public class IsTest extends AbstractMatcherTest {
17+
public final class IsTest {
1018

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);
1425
}
1526

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);
2133
}
2234

23-
public void testGeneratesIsPrefixInDescription() {
35+
@Test public void
36+
generatesIsPrefixInDescription() {
2437
assertDescription("is <true>", is(equalTo(true)));
38+
assertDescription("is \"A\"", is("A"));
2539
}
2640

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");
3347
}
3448

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);
3956
}
4057
}

0 commit comments

Comments
 (0)