Skip to content

Commit fcc7889

Browse files
committed
convert to JUnit4 and correct describeMismatch
1 parent 79aa25d commit fcc7889

2 files changed

Lines changed: 50 additions & 29 deletions

File tree

‎hamcrest-library/src/main/java/org/hamcrest/text/IsEqualIgnoringCase.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public boolean matchesSafely(String item) {
3131

3232
@Override
3333
public void describeMismatchSafely(String item, Description mismatchDescription) {
34-
mismatchDescription.appendText("was ").appendText(item);
34+
mismatchDescription.appendText("was ").appendValue(item);
3535
}
3636

3737
@Override

‎hamcrest-library/src/test/java/org/hamcrest/text/IsEqualIgnoringCaseTest.java‎

Lines changed: 49 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,47 +2,68 @@
22
*/
33
package org.hamcrest.text;
44

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;
911
import static org.hamcrest.text.IsEqualIgnoringCase.equalToIgnoringCase;
1012

11-
public class IsEqualIgnoringCaseTest extends AbstractMatcherTest {
13+
import org.hamcrest.Matcher;
14+
import org.junit.Test;
15+
16+
public final class IsEqualIgnoringCaseTest {
1217

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);
1624
}
1725

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+
}
2235

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");
2442
}
2543

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);
2949
}
3050

31-
public void testFailsIfMatchingAgainstNull() {
32-
assertThat(null, not(equalToIgnoringCase("heLLo")));
51+
@Test(expected=IllegalArgumentException.class) public void
52+
canOnlyBeConstructedAboutANonNullString() {
53+
equalToIgnoringCase(null);
3354
}
3455

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);
4261
}
4362

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");
4768
}
4869
}

0 commit comments

Comments
 (0)