Reputation: 3769
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.
Upvotes: 3
Views: 4495
Reputation: 2376
Try adding a log.getLog().trim()
and removing the \n from the end of your expected string.
Upvotes: 5