diff options
| author | Stefan Bodewig <bodewig@apache.org> | 2020-05-05 14:51:38 +0200 |
|---|---|---|
| committer | Stefan Bodewig <bodewig@apache.org> | 2020-05-05 14:51:38 +0200 |
| commit | fe7e9617ed54bb4aeae2e79871d022cbfdddbf3d (patch) | |
| tree | 0bb6c948c40a924497aeefae5a66fd84e1c9c99e /src/tests/junit/org | |
| parent | bc9fed1198acf599173334f5e90a855ea5077fc7 (diff) | |
| parent | 9c1f4d905da59bf446570ac28df5b68a37281f35 (diff) | |
| download | ant-fe7e9617ed54bb4aeae2e79871d022cbfdddbf3d.tar.gz | |
Merge branch '1.9.x'
Diffstat (limited to 'src/tests/junit/org')
| -rw-r--r-- | src/tests/junit/org/apache/tools/ant/util/FileUtilsTest.java | 62 |
1 files changed, 51 insertions, 11 deletions
diff --git a/src/tests/junit/org/apache/tools/ant/util/FileUtilsTest.java b/src/tests/junit/org/apache/tools/ant/util/FileUtilsTest.java index 5f68b80db..fc584563d 100644 --- a/src/tests/junit/org/apache/tools/ant/util/FileUtilsTest.java +++ b/src/tests/junit/org/apache/tools/ant/util/FileUtilsTest.java @@ -29,6 +29,7 @@ import java.util.Optional; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.MagicTestNames; +import org.apache.tools.ant.Project; import org.apache.tools.ant.taskdefs.condition.Os; import org.junit.Before; import org.junit.Rule; @@ -355,9 +356,14 @@ public class FileUtilsTest { */ @Test public void testCreateTempFile() throws IOException { - // null parent dir - File tmp1 = getFileUtils().createTempFile("pre", ".suf", null, false, true); - String tmploc = System.getProperty("java.io.tmpdir"); + final String tmploc = System.getProperty("java.io.tmpdir"); + final Project projectWithoutTempDir = new Project(); + final Project projectWithTempDir = new Project(); + final File projectTmpDir = folder.newFolder("subdir"); + projectWithTempDir.setProperty("ant.tmpdir", projectTmpDir.getAbsolutePath()); + + // null parent dir, null project + File tmp1 = getFileUtils().createTempFile(null, "pre", ".suf", null, false, true); String name = tmp1.getName(); assertThat("starts with pre", name, startsWith("pre")); assertThat("ends with .suf", name, endsWith(".suf")); @@ -366,9 +372,29 @@ public class FileUtilsTest { tmp1.getAbsolutePath()); tmp1.delete(); + // null parent dir, project without magic property + tmp1 = getFileUtils().createTempFile(projectWithoutTempDir, "pre", ".suf", null, false, true); + name = tmp1.getName(); + assertTrue("starts with pre", name.startsWith("pre")); + assertTrue("ends with .suf", name.endsWith(".suf")); + assertTrue("File was created", tmp1.exists()); + assertEquals((new File(tmploc, tmp1.getName())).getAbsolutePath(), tmp1 + .getAbsolutePath()); + tmp1.delete(); + + // null parent dir, project with magic property + tmp1 = getFileUtils().createTempFile(projectWithTempDir, "pre", ".suf", null, false, true); + name = tmp1.getName(); + assertTrue("starts with pre", name.startsWith("pre")); + assertTrue("ends with .suf", name.endsWith(".suf")); + assertTrue("File was created", tmp1.exists()); + assertEquals((new File(projectTmpDir, tmp1.getName())).getAbsolutePath(), tmp1 + .getAbsolutePath()); + tmp1.delete(); + File dir2 = folder.newFolder("ant-test"); - File tmp2 = getFileUtils().createTempFile("pre", ".suf", dir2, true, true); + File tmp2 = getFileUtils().createTempFile(null, "pre", ".suf", dir2, true, true); String name2 = tmp2.getName(); assertThat("starts with pre", name2, startsWith("pre")); assertThat("ends with .suf", name2, endsWith(".suf")); @@ -377,6 +403,25 @@ public class FileUtilsTest { tmp2.getAbsolutePath()); tmp2.delete(); + tmp2 = getFileUtils().createTempFile(projectWithoutTempDir, "pre", ".suf", dir2, true, true); + name2 = tmp2.getName(); + assertTrue("starts with pre", name2.startsWith("pre")); + assertTrue("ends with .suf", name2.endsWith(".suf")); + assertTrue("File was created", tmp2.exists()); + assertEquals((new File(dir2, tmp2.getName())).getAbsolutePath(), tmp2 + .getAbsolutePath()); + tmp2.delete(); + + tmp2 = getFileUtils().createTempFile(projectWithTempDir, "pre", ".suf", dir2, true, true); + name2 = tmp2.getName(); + assertTrue("starts with pre", name2.startsWith("pre")); + assertTrue("ends with .suf", name2.endsWith(".suf")); + assertTrue("File was created", tmp2.exists()); + assertEquals((new File(dir2, tmp2.getName())).getAbsolutePath(), tmp2 + .getAbsolutePath()); + tmp2.delete(); + dir2.delete(); + File parent = new File((new File("/tmp")).getAbsolutePath()); tmp1 = getFileUtils().createTempFile("pre", ".suf", parent, false); assertFalse("new file", tmp1.exists()); @@ -388,13 +433,8 @@ public class FileUtilsTest { .getParent()); tmp2 = getFileUtils().createTempFile("pre", ".suf", parent, false); - assertNotEquals("files are different", tmp1.getAbsolutePath(), tmp2.getAbsolutePath()); - - // null parent dir - File tmp3 = getFileUtils().createTempFile("pre", ".suf", null, false); - tmploc = System.getProperty("java.io.tmpdir"); - assertEquals((new File(tmploc, tmp3.getName())).getAbsolutePath(), - tmp3.getAbsolutePath()); + assertTrue("files are different", !tmp1.getAbsolutePath().equals( + tmp2.getAbsolutePath())); } /** |
