Skip to content

Commit

Permalink
Use platform-specific line separators
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
albertdev authored and tumbarumba committed Aug 28, 2019
1 parent c1ea49a commit 2951069
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
6 changes: 4 additions & 2 deletions hamcrest/src/main/java/org/hamcrest/MatcherAssert.java
Expand Up @@ -10,9 +10,11 @@ public static <T> void assertThat(String reason, T actual, Matcher<? super T> ma
if (!matcher.matches(actual)) {
Description description = new StringDescription();
description.appendText(reason)
.appendText("\nExpected: ")
.appendText(System.lineSeparator())
.appendText("Expected: ")
.appendDescriptionOf(matcher)
.appendText("\n but: ");
.appendText(System.lineSeparator())
.appendText(" but: ");
matcher.describeMismatch(actual, description);

throw new AssertionError(description.toString());
Expand Down
9 changes: 6 additions & 3 deletions hamcrest/src/test/java/org/hamcrest/MatcherAssertTest.java
Expand Up @@ -12,8 +12,9 @@ public final class MatcherAssertTest {
includesDescriptionOfTestedValueInErrorMessage() {
String expected = "expected";
String actual = "actual";
String endLine = System.lineSeparator();

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

try {
assertThat("identifier", actual, equalTo(expected));
Expand All @@ -30,8 +31,9 @@ public final class MatcherAssertTest {
descriptionCanBeElided() {
String expected = "expected";
String actual = "actual";
String endLine = System.lineSeparator();

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

try {
assertThat(actual, equalTo(expected));
Expand Down Expand Up @@ -78,7 +80,8 @@ public void describeMismatch(Object item, Description mismatchDescription) {
}
};

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

try {
assertThat("Value", matcherWithCustomMismatchDescription);
Expand Down

0 comments on commit 2951069

Please sign in to comment.