|
2 | 2 | */ |
3 | 3 | package org.hamcrest.core; |
4 | 4 |
|
5 | | -import static org.hamcrest.core.IsSame.theInstance; |
| 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; |
6 | 10 | import static org.hamcrest.core.IsSame.sameInstance; |
7 | | -import static org.hamcrest.core.IsNot.not; |
8 | | -import org.hamcrest.AbstractMatcherTest; |
| 11 | +import static org.hamcrest.core.IsSame.theInstance; |
| 12 | + |
9 | 13 | import org.hamcrest.Matcher; |
10 | | -import static org.hamcrest.MatcherAssert.assertThat; |
| 14 | +import org.junit.Test; |
11 | 15 |
|
12 | 16 |
|
13 | | -public class IsSameTest extends AbstractMatcherTest { |
| 17 | +public final class IsSameTest { |
14 | 18 |
|
15 | | - @Override |
16 | | - protected Matcher<?> createMatcher() { |
17 | | - return sameInstance("irrelevant"); |
| 19 | + @Test public void |
| 20 | + copesWithNullsAndUnknownTypes() { |
| 21 | + Matcher<String> matcher = sameInstance("irrelevant"); |
| 22 | + |
| 23 | + assertNullSafe(matcher); |
| 24 | + assertUnknownTypeSafe(matcher); |
18 | 25 | } |
19 | 26 |
|
20 | | - public void testEvaluatesToTrueIfArgumentIsReferenceToASpecifiedObject() { |
| 27 | + @Test public void |
| 28 | + evaluatesToTrueIfArgumentIsReferenceToASpecifiedObject() { |
21 | 29 | Object o1 = new Object(); |
22 | | - Object o2 = new Object(); |
| 30 | + Matcher<Object> matcher = sameInstance(o1); |
23 | 31 |
|
24 | | - assertThat(o1, sameInstance(o1)); |
25 | | - assertThat(o2, not(sameInstance(o1))); |
| 32 | + assertMatches("didn't match", matcher, o1); |
| 33 | + assertDoesNotMatch("matched unexpectedly", matcher, new Object()); |
26 | 34 | } |
27 | 35 |
|
28 | | - public void testAlternativeFactoryMethodAlsoMatchesOnlyIfArgumentIsReferenceToASpecifiedObject() { |
| 36 | + @Test public void |
| 37 | + alternativeFactoryMethodAlsoMatchesOnlyIfArgumentIsReferenceToASpecifiedObject() { |
29 | 38 | Object o1 = new Object(); |
30 | | - Object o2 = new Object(); |
31 | | - |
32 | | - assertThat(o1, theInstance(o1)); |
33 | | - assertThat(o2, not(theInstance(o1))); |
| 39 | + Matcher<Object> matcher = theInstance(o1); |
| 40 | + |
| 41 | + assertMatches("didn't match", matcher, o1); |
| 42 | + assertDoesNotMatch("matched unexpectedly", matcher, new Object()); |
34 | 43 | } |
35 | 44 |
|
36 | | - public void testReturnsReadableDescriptionFromToString() { |
| 45 | + @Test public void |
| 46 | + returnsReadableDescriptionFromToString() { |
37 | 47 | assertDescription("sameInstance(\"ARG\")", sameInstance("ARG")); |
38 | 48 | } |
39 | 49 |
|
40 | | - public void testReturnsReadableDescriptionFromToStringWhenInitialisedWithNull() { |
| 50 | + @Test public void |
| 51 | + returnsReadableDescriptionFromToStringWhenInitialisedWithNull() { |
41 | 52 | assertDescription("sameInstance(null)", sameInstance(null)); |
42 | 53 | } |
43 | 54 | } |
0 commit comments