AssertEquals(String, String) ComparisonFailure when contents are identical

The visible characters are identical, but the non-printable characters are not.

You are comparing expected output containing CRLF (\r\n) to actual output with just LF (\n). You can see that in IntelliJ above the right-hand side of both text areas.

Simple solution is to replace the \n's in your string with \r\n. Or remove \r from the other.


It is also worth noting that the parameter ordering is actually (Object expected, Object actual), so the outContent should go second since that is the "actual" output.


You can use AssertJ "isEqualToNormalizingNewline" as in:

import static org.assertj.core.api.Assertions.assertThat;

...

@Test
public void ingoreLineEndingCharacterTest() {
    assertThat("First Line\nSecond Line\n").isEqualToNormalizingNewlines("First Line\r\nSecond Line\r\n");
}