I have a test like this:
String dir = "/foo";
String fileName = "hello.txt";
String pathString = dir + "/" + fileName;
String text = "hello world!";
MyTask task = new MyTask();
FileSystem fs = Jimfs.newFileSystem(Configuration.unix());
Path foo = fs.getPath(dir);
Files.createDirectory(foo);
Path hello = foo.resolve(fileName);
Files.write(hello, ImmutableList.of(text), StandardCharsets.UTF_8);
task.setFileSystem(fs);
String fileValue = task.readFile(pathString);
// Doing this just shows "fail whale: hello world!"
// fail("fail whale: " + fileValue);
// Failure from here adds brackets
assertEquals(text, fileValue);
I get a failure like this:
org.junit.ComparisonFailure: expected:<hello world![]> but was:<hello world![
]>
If I reverse the arguments, I can see that readFile
is definitely creating that new line, and it's not just my terminal truncating.
I have no idea why JUnit is showing brackets after my string at all, and am even more confused as to why a space would get added.
readFile
is simply this:
public String readFile(String path) {
try {
return new String(Files.readAllBytes(fs.getPath(path)));
} catch (Exception e) {
e.printStackTrace();
return "";
}
}
Java: Is assertEquals(String, String) reliable? makes reference of the String
being an Object
, but if that is the case, an the brackets just imply Object
, still really confused about that new line.