I only have this mac, and I am wondering if this problem exists for other OS or, possibly, for jdks. This test failed when the second line in the last verifies that the absolute path refers to the real file (and matches the first path of the paragraph in the file). BUT calling f2.exists returns false as if it did not exist.
I am curious on windows and linux if this also fails?
@Test public void testUserDirProp() { File f = new File("src/test/resources/logback-test.xml"); //assert absolute path is correct Assert.assertEquals("/Library/Workflow/webpieces/core/core-util/src/test/resources/logback-test.xml", f.getAbsolutePath()); Assert.assertTrue(f.exists()); //NOW, change user.dir System.setProperty("user.dir", "/Library/Workflow/webpieces/core/core-util/src"); //Now, f2 is relative to NEW user.dir property File f2 = new File("test/resources/logback-test.xml"); //verify absolute path is still the full correct path for f2 and it is Assert.assertEquals("/Library/Workflow/webpieces/core/core-util/src/test/resources/logback-test.xml", f2.getAbsolutePath()); //since absolute path was correct, it should exist Assert.assertTrue(f2.exists()); }
java
Dean Hiller Jul 16 '17 at 16:06 2017-07-16 16:06
source share