The following JUnit 4 test works fine under Linux and Windows:
public class TmpFileTest {
@Rule
public TemporaryFolder tmp = new TemporaryFolder();
@Test
public void test() throws Exception {
File tmpFile = tmp.newFile();
Assert.assertEquals(tmpFile, tmpFile.getCanonicalFile());
}
}
But the assertion fails on Mac (tested with Sierra 10.12.4):
java.lang.AssertionError:
Expected :/var/folders/q4/rj3wqzms2fdcqlxgdzb3l5hc0000gn/T/junit1451860092188597816/junit1906079638039608483.tmp
Actual :/private/var/folders/q4/rj3wqzms2fdcqlxgdzb3l5hc0000gn/T/junit1451860092188597816/junit1906079638039608483.tmp
var
is a symlink that points to private/var
, which is resolved via File#getCanonicalFile()
—this is the difference.
Is there a way to fix this? This causes a bunch of test failures on my machine.