3

I have a test, I want to assert its result:

    assertThat(cofmanString, new IsEqualIgnoringCase(FileUtils.readFileToString(new File("/Users/myFile.txt"))));

in Intellij I see the strings are identical including tabs and newlines

actual:

enter image description here

expected: enter image description here

but the test fails like this:

enter image description here

which hamcrest matcher can i use to compare the strings and succeed?

Elad Benda2
  • 13,852
  • 29
  • 82
  • 157

2 Answers2

4

You can use this:

assertThat(cofmanString, equalToIgnoringWhiteSpace(FileUtils.readFileToString(
new File("/Users/myFile.txt")).toLowerCase()));

You can see more for IsEqualIgnoringWhiteSpace here

ddarellis
  • 3,912
  • 3
  • 25
  • 53
1

There is no "ignore tabs" option, but you can just remove all tabs before comparing by applying .replace("\t", "") to each term:

assertThat(cofmanString.replace("\t", ""), new IsEqualIgnoringCase(
  FileUtils.readFileToString(new File("/Users/myFile.txt"))).replace("\t", ""));
Bohemian
  • 412,405
  • 93
  • 575
  • 722