|
2 | 2 | */ |
3 | 3 | package org.hamcrest.text; |
4 | 4 |
|
5 | | -import org.hamcrest.AbstractMatcherTest; |
6 | | -import org.hamcrest.Matcher; |
7 | | -import static org.hamcrest.MatcherAssert.assertThat; |
8 | | -import static org.hamcrest.core.IsNot.not; |
| 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; |
9 | 11 | import static org.hamcrest.text.IsEqualIgnoringCase.equalToIgnoringCase; |
10 | 12 |
|
11 | | -public class IsEqualIgnoringCaseTest extends AbstractMatcherTest { |
| 13 | +import org.hamcrest.Matcher; |
| 14 | +import org.junit.Test; |
| 15 | + |
| 16 | +public final class IsEqualIgnoringCaseTest { |
12 | 17 |
|
13 | | - @Override |
14 | | - protected Matcher<?> createMatcher() { |
15 | | - return equalToIgnoringCase("irrelevant"); |
| 18 | + @Test public void |
| 19 | + copesWithNullsAndUnknownTypes() { |
| 20 | + Matcher<String> matcher = equalToIgnoringCase("irrelevant"); |
| 21 | + |
| 22 | + assertNullSafe(matcher); |
| 23 | + assertUnknownTypeSafe(matcher); |
16 | 24 | } |
17 | 25 |
|
18 | | - public void testIgnoresCaseOfCharsInString() { |
19 | | - assertThat("HELLO", equalToIgnoringCase("heLLo")); |
20 | | - assertThat("hello", equalToIgnoringCase("heLLo")); |
21 | | - assertThat("HelLo", equalToIgnoringCase("heLLo")); |
| 26 | + @Test public void |
| 27 | + ignoresCaseOfCharsInString() { |
| 28 | + final Matcher<String> matcher = equalToIgnoringCase("heLLo"); |
| 29 | + |
| 30 | + assertMatches("didn't match", matcher, "HELLO"); |
| 31 | + assertMatches("didn't match", matcher, "hello"); |
| 32 | + assertMatches("didn't match", matcher, "HelLo"); |
| 33 | + assertDoesNotMatch("matched unexpectedly", matcher, "bye"); |
| 34 | + } |
22 | 35 |
|
23 | | - assertThat("bye", not(equalToIgnoringCase("heLLo"))); |
| 36 | + @Test public void |
| 37 | + mismatchesIfAdditionalWhitespaceIsPresent() { |
| 38 | + final Matcher<String> matcher = equalToIgnoringCase("heLLo"); |
| 39 | + |
| 40 | + assertDoesNotMatch("matched unexpectedly", matcher, "hello "); |
| 41 | + assertDoesNotMatch("matched unexpectedly", matcher, " hello"); |
24 | 42 | } |
25 | 43 |
|
26 | | - public void testFailsIfAdditionalWhitespaceIsPresent() { |
27 | | - assertThat("heLLo ", not(equalToIgnoringCase("heLLo"))); |
28 | | - assertThat(" heLLo", not(equalToIgnoringCase("heLLo"))); |
| 44 | + @Test public void |
| 45 | + mismatchesNull() { |
| 46 | + final Matcher<String> matcher = equalToIgnoringCase("heLLo"); |
| 47 | + |
| 48 | + assertDoesNotMatch("matched unexpectedly", matcher, null); |
29 | 49 | } |
30 | 50 |
|
31 | | - public void testFailsIfMatchingAgainstNull() { |
32 | | - assertThat(null, not(equalToIgnoringCase("heLLo"))); |
| 51 | + @Test(expected=IllegalArgumentException.class) public void |
| 52 | + canOnlyBeConstructedAboutANonNullString() { |
| 53 | + equalToIgnoringCase(null); |
33 | 54 | } |
34 | 55 |
|
35 | | - public void testRequiresNonNullStringToBeConstructed() { |
36 | | - try { |
37 | | - equalToIgnoringCase(null); |
38 | | - fail("Expected exception"); |
39 | | - } catch (IllegalArgumentException goodException) { |
40 | | - // expected! |
41 | | - } |
| 56 | + |
| 57 | + @Test public void |
| 58 | + describesItself() { |
| 59 | + final Matcher<String> matcher = equalToIgnoringCase("heLLo"); |
| 60 | + assertDescription("equalToIgnoringCase(\"heLLo\")", matcher); |
42 | 61 | } |
43 | 62 |
|
44 | | - public void testDescribesItselfAsCaseInsensitive() { |
45 | | - assertDescription("equalToIgnoringCase(\"heLLo\")", |
46 | | - equalToIgnoringCase("heLLo")); |
| 63 | + @Test public void |
| 64 | + describesAMismatch() { |
| 65 | + final Matcher<String> matcher = equalToIgnoringCase("heLLo"); |
| 66 | + String expectedMismatchString = "was \"Cheese\""; |
| 67 | + assertMismatchDescription(expectedMismatchString, matcher, "Cheese"); |
47 | 68 | } |
48 | 69 | } |
0 commit comments