Rajkishan Swami
Rajkishan Swami

Reputation: 3769

Identical Content But JUnit Test Fails(IntelliJ)

I have a JUnit Test that compares two strings:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = CDPlayerConfig.class)
public class CDPlayerTest {

    @Rule
    public final SystemOutRule log = new SystemOutRule().enableLog();

    @Autowired
    private CompactDisc cd;

    @Autowired
    private MediaPlayer player;

    @Test
    public void cdShouldNotBeNull() {
        assertNotNull(cd);
    }

    @Test
    public void play() {
        player.play();
        assertEquals("Playing title Sgt. Pepper's Lonely Hearts Club Band by artist The Beatles\n",
                log.getLog());
    }
}

I'm getting a org.junit.ComparisonFailure exception on the second test. However, IntelliJ shows contents are identical. What am I missing?

EDIT: Added back the \n at the end of the expected string.

enter image description here

Upvotes: 3

Views: 4495

Answers (2)

Craig
Craig

Reputation: 2376

Try adding a log.getLog().trim() and removing the \n from the end of your expected string.

Upvotes: 5

Marcin Szymczak
Marcin Szymczak

Reputation: 11443

You have different end line sign (LF vs CRLF)

Upvotes: 5

Related Questions