From f0fbdc5299ed7f575764934e635792109b84579b Mon Sep 17 00:00:00 2001 From: JAYA DILEEP Date: Sat, 5 Sep 2026 15:04:39 +0000 Subject: [PATCH] Use System.lineSeparator() in OptionalMatchersTest expectations Hardcoded LF in expected AssertionError messages fails on Windows. Use System.lineSeparator() so the tests pass across platforms. Fixes #438 Signed-off-by: JAYA DILEEP --- .../optional/OptionalMatchersTest.java | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/hamcrest/src/test/java/org/hamcrest/optional/OptionalMatchersTest.java b/hamcrest/src/test/java/org/hamcrest/optional/OptionalMatchersTest.java index 3af6309c..cbf56d4e 100644 --- a/hamcrest/src/test/java/org/hamcrest/optional/OptionalMatchersTest.java +++ b/hamcrest/src/test/java/org/hamcrest/optional/OptionalMatchersTest.java @@ -15,6 +15,8 @@ public class OptionalMatchersTest { + private static final String NL = System.lineSeparator(); + @Test public void checkEmptyOptional() { assertThat(Optional.empty(), is(emptyOptional())); @@ -26,8 +28,8 @@ public void checkEmptyOptionalFailure() { AssertionError failure = assertThrows(AssertionError.class, () -> { assertThat(Optional.of(1), emptyOptional()); }); - assertEquals("\n" + - "Expected: empty\n" + + assertEquals(NL + + "Expected: empty" + NL + " but: is Optional[1]", failure.getMessage()); } @@ -36,8 +38,8 @@ public void checkEmptyOptionalIsFailure() { AssertionError failure = assertThrows(AssertionError.class, () -> { assertThat(Optional.of(1), is(emptyOptional())); }); - assertEquals("\n" + - "Expected: is empty\n" + + assertEquals(NL + + "Expected: is empty" + NL + " but: is Optional[1]", failure.getMessage()); } @@ -46,8 +48,8 @@ public void checkEmptyOptionalIsNotFailure() { AssertionError failure = assertThrows(AssertionError.class, () -> { assertThat(Optional.empty(), is(not(emptyOptional()))); }); - assertEquals("\n" + - "Expected: is not empty\n" + + assertEquals(NL + + "Expected: is not empty" + NL + " but: was ", failure.getMessage()); } @@ -76,8 +78,8 @@ public void checkWithValueFailure() { AssertionError failure = assertThrows(AssertionError.class, () -> { assertThat(Optional.empty(), is(optionalWithValue())); }); - assertEquals("\n" + - "Expected: is present and matches any\n" + + assertEquals(NL + + "Expected: is present and matches any" + NL + " but: is Optional.empty", failure.getMessage()); } @@ -86,8 +88,8 @@ public void checkWithMatchingValueFailure() { AssertionError failure = assertThrows(AssertionError.class, () -> { assertThat(Optional.empty(), is(optionalWithValue(equalTo(1)))); }); - assertEquals("\n" + - "Expected: is present and matches <1>\n" + + assertEquals(NL + + "Expected: is present and matches <1>" + NL + " but: is Optional.empty", failure.getMessage()); } @@ -96,8 +98,8 @@ public void checkWithLiteralValueFailure() { AssertionError failure = assertThrows(AssertionError.class, () -> { assertThat(Optional.of("text"), is(optionalWithValue("Hello, world"))); }); - assertEquals("\n" + - "Expected: is present and matches \"Hello, world\"\n" + + assertEquals(NL + + "Expected: is present and matches \"Hello, world\"" + NL + " but: is Optional[text]", failure.getMessage()); } }