2

I am writing a unit test and I am seeing the following which I don't understand. Any help is appreciated.

tempFile = File.createTempFile("temp", "file");
Files.write(tempFile.toPath(), expectedBytes);
byte[] b = Files.readAllBytes(tempFile.toPath());
Assert.equals(b, expectedBytes); // failed
Isa
  • 353
  • 2
  • 18
  • 2
    a byte array is only equal to itself. Not to any other byte array, even if the other array has the same bytes. The same goes for all arrays, by the way. – JB Nizet Jun 29 '18 at 16:34
  • 2
    Try Assert.assertArrayEquals() instead (assuming JUnit here). – t6nn Jun 29 '18 at 16:37

1 Answers1

2

Arrays do not support deep comparison with equals. Check if that Assert class has an arrayEquals method.

Leo Aso
  • 11,898
  • 3
  • 25
  • 46