Skip to content

Commit ffa14cb

Browse files
committed
ignore case for ends-with
1 parent c0058c6 commit ffa14cb

2 files changed

Lines changed: 12 additions & 11 deletions

File tree

‎hamcrest-core/src/main/java/org/hamcrest/core/StringEndsWith.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class StringEndsWith extends SubstringMatcher {
1313

1414
@Override
1515
protected boolean evalSubstringOf(String s) {
16-
return s.endsWith(substring);
16+
return s.toLowerCase().endsWith(substring.toLowerCase());
1717
}
1818

1919
/**

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package org.hamcrest.core;
44

55
import static org.hamcrest.core.StringEndsWith.endsWith;
6+
import static org.hamcrest.core.StringEndsWith.endsWithIgnoringCase;
67

78
import org.hamcrest.AbstractMatcherTest;
89
import org.hamcrest.Matcher;
@@ -30,16 +31,16 @@ public void testMatchesSubstringAtEnd() {
3031
}
3132

3233
public void testMatchesSubstringAtEndIngoringCase() {
33-
final Matcher<String> ingoringCase = endsWith("EXCERpt");
34-
assertDoesNotMatch(ingoringCase, "eXCErpt" + "END");
35-
assertMatches(ingoringCase, "START" + "EXceRpt");
36-
assertMatches(ingoringCase, "EXcerPT");
37-
assertDoesNotMatch(ingoringCase, "START" + "ExcERpt" + "END");
38-
assertMatches(ingoringCase, "exCERpt" + "EXCerPt");
39-
assertDoesNotMatch(ingoringCase, "ExcER");
40-
41-
assertMismatchDescription("was \"Something else\"", ingoringCase, "Something else");
42-
assertDescription("a string ending with \"EXCERpt\" ignoring case", ingoringCase);
34+
final Matcher<String> ignoringCase = endsWithIgnoringCase("EXCERpt");
35+
assertDoesNotMatch(ignoringCase, "eXCErpt" + "END");
36+
assertMatches(ignoringCase, "START" + "EXceRpt");
37+
assertMatches(ignoringCase, "EXcerPT");
38+
assertDoesNotMatch(ignoringCase, "START" + "ExcERpt" + "END");
39+
assertMatches(ignoringCase, "exCERpt" + "EXCerPt");
40+
assertDoesNotMatch(ignoringCase, "ExcER");
41+
42+
assertMismatchDescription("was \"Something else\"", ignoringCase, "Something else");
43+
assertDescription("a string ending with \"EXCERpt\" ignoring case", ignoringCase);
4344
}
4445

4546
}

0 commit comments

Comments
 (0)