Skip to content

Commit 2951069

Browse files
albertdevtumbarumba
authored andcommitted
Use platform-specific line separators
The `System.lineSeparator()` function will return the end of line separator appropriate for the current runtime, i.e. "\r\n" on Windows and "\n" on Unix.
1 parent c1ea49a commit 2951069

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

hamcrest/src/main/java/org/hamcrest/MatcherAssert.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ public static <T> void assertThat(String reason, T actual, Matcher<? super T> ma
1010
if (!matcher.matches(actual)) {
1111
Description description = new StringDescription();
1212
description.appendText(reason)
13-
.appendText("\nExpected: ")
13+
.appendText(System.lineSeparator())
14+
.appendText("Expected: ")
1415
.appendDescriptionOf(matcher)
15-
.appendText("\n but: ");
16+
.appendText(System.lineSeparator())
17+
.appendText(" but: ");
1618
matcher.describeMismatch(actual, description);
1719

1820
throw new AssertionError(description.toString());

hamcrest/src/test/java/org/hamcrest/MatcherAssertTest.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ public final class MatcherAssertTest {
1212
includesDescriptionOfTestedValueInErrorMessage() {
1313
String expected = "expected";
1414
String actual = "actual";
15+
String endLine = System.lineSeparator();
1516

16-
String expectedMessage = "identifier\nExpected: \"expected\"\n but: was \"actual\"";
17+
String expectedMessage = "identifier" + endLine + "Expected: \"expected\"" + endLine + " but: was \"actual\"";
1718

1819
try {
1920
assertThat("identifier", actual, equalTo(expected));
@@ -30,8 +31,9 @@ public final class MatcherAssertTest {
3031
descriptionCanBeElided() {
3132
String expected = "expected";
3233
String actual = "actual";
34+
String endLine = System.lineSeparator();
3335

34-
String expectedMessage = "\nExpected: \"expected\"\n but: was \"actual\"";
36+
String expectedMessage = endLine + "Expected: \"expected\"" + endLine + " but: was \"actual\"";
3537

3638
try {
3739
assertThat(actual, equalTo(expected));
@@ -78,7 +80,8 @@ public void describeMismatch(Object item, Description mismatchDescription) {
7880
}
7981
};
8082

81-
String expectedMessage = "\nExpected: Something cool\n but: Not cool";
83+
String endLine = System.lineSeparator();
84+
String expectedMessage = endLine + "Expected: Something cool" + endLine + " but: Not cool";
8285

8386
try {
8487
assertThat("Value", matcherWithCustomMismatchDescription);

0 commit comments

Comments
 (0)