Skip to content

Commit efe363e

Browse files
committed
convert to JUnit 4
1 parent 4d66107 commit efe363e

1 file changed

Lines changed: 53 additions & 37 deletions

File tree

‎hamcrest-core/src/test/java/org/hamcrest/core/IsInstanceOfTest.java‎

Lines changed: 53 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,59 +2,75 @@
22
*/
33
package org.hamcrest.core;
44

5-
import org.hamcrest.AbstractMatcherTest;
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.assertMismatchDescription;
9+
import static org.hamcrest.AbstractMatcherTest.assertNullSafe;
10+
import static org.hamcrest.AbstractMatcherTest.assertUnknownTypeSafe;
11+
import static org.hamcrest.core.IsInstanceOf.any;
12+
import static org.hamcrest.core.IsInstanceOf.instanceOf;
13+
614
import org.hamcrest.Matcher;
7-
import static org.hamcrest.MatcherAssert.assertThat;
8-
import static org.hamcrest.core.IsInstanceOf.*;
9-
import static org.hamcrest.core.IsNot.not;
15+
import org.junit.Test;
16+
17+
public final class IsInstanceOfTest {
1018

11-
public class IsInstanceOfTest extends AbstractMatcherTest {
19+
@Test public void
20+
copesWithNullsAndUnknownTypes() {
21+
Matcher<?> matcher = instanceOf(Number.class);
1222

13-
@Override
14-
protected Matcher<?> createMatcher() {
15-
return instanceOf(Number.class);
23+
assertNullSafe(matcher);
24+
assertUnknownTypeSafe(matcher);
1625
}
1726

18-
public void testEvaluatesToTrueIfArgumentIsInstanceOfASpecificClass() {
19-
assertThat(1, instanceOf(Number.class));
20-
assertThat(1.0, instanceOf(Number.class));
21-
assertThat(null, not(instanceOf(Number.class)));
22-
assertThat(new Object(), not(instanceOf(Number.class)));
27+
@Test public void
28+
evaluatesToTrueIfArgumentIsInstanceOfASpecificClass() {
29+
final Matcher<Object> matcher = instanceOf(Number.class);
30+
31+
assertMatches("didn't match", matcher, 1);
32+
assertMatches("didn't match", matcher, 1.1);
33+
assertDoesNotMatch("matched unexpectedly", matcher, null);
34+
assertDoesNotMatch("matched unexpectedly", matcher, new Object());
2335
}
2436

25-
public void testHasAReadableDescription() {
37+
@Test public void
38+
hasAReadableDescription() {
2639
assertDescription("an instance of java.lang.Number", instanceOf(Number.class));
2740
}
2841

29-
public void testDescribesActualClassInMismatchMessage() {
30-
assertMismatchDescription("\"some text\" is a java.lang.String", instanceOf(Number.class), "some text");
42+
@Test public void
43+
describesActualClassInMismatchMessage() {
44+
assertMismatchDescription("\"some text\" is a java.lang.String", instanceOf(Number.class), "some text");
3145
}
3246

33-
public void testMatchesPrimitiveTypes() {
34-
assertThat(true, any(boolean.class));
35-
assertThat((byte)1, any(byte.class));
36-
assertThat('x', any(char.class));
37-
assertThat(5.0, any(double.class));
38-
assertThat(5.0f, any(float.class));
39-
assertThat(2, any(int.class));
40-
assertThat(4L, any(long.class));
41-
assertThat((short)1, any(short.class));
47+
@Test public void
48+
matchesPrimitiveTypes() {
49+
assertMatches("didn't match", any(boolean.class), true);
50+
assertMatches("didn't match", any(byte.class), (byte)1);
51+
assertMatches("didn't match", any(char.class), 'x');
52+
assertMatches("didn't match", any(double.class), 5.0);
53+
assertMatches("didn't match", any(float.class), 5.0f);
54+
assertMatches("didn't match", any(int.class), 2);
55+
assertMatches("didn't match", any(long.class), 4L);
56+
assertMatches("didn't match", any(short.class), (short)1);
4257
}
43-
44-
public void testInstanceOfRequiresACastToReturnTheCorrectTypeForUseInJMock() {
45-
@SuppressWarnings("unused")
46-
Integer anInteger = (Integer)with(instanceOf(Integer.class));
58+
59+
@Test public void
60+
instanceOfRequiresACastToReturnTheCorrectTypeForUseInJMock() {
61+
@SuppressWarnings("unused")
62+
Integer anInteger = (Integer)with(instanceOf(Integer.class));
4763
}
48-
49-
public void testAnyWillReturnTheCorrectTypeForUseInJMock() {
50-
@SuppressWarnings("unused")
51-
Integer anInteger = with(any(Integer.class));
64+
65+
@Test public void
66+
anyWillReturnTheCorrectTypeForUseInJMock() {
67+
@SuppressWarnings("unused")
68+
Integer anInteger = with(any(Integer.class));
5269
}
53-
54-
70+
71+
5572
private static <T> T with(@SuppressWarnings("unused") Matcher<T> matcher) {
56-
return null;
73+
return null;
5774
}
58-
5975
}
6076

0 commit comments

Comments
 (0)