ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject svn commit: r574381 - /ant/core/trunk/src/tests/junit/org/apache/tools/ant/util/FileUtilsTest.java
Date Mon, 10 Sep 2007 21:38:52 GMT
Author: jkf
Date: Mon Sep 10 14:38:52 2007
New Revision: 574381

URL: http://svn.apache.org/viewvc?rev=574381&view=rev
Log:
TempFile changes (ctd)

Modified:
    ant/core/trunk/src/tests/junit/org/apache/tools/ant/util/FileUtilsTest.java

Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/util/FileUtilsTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/util/FileUtilsTest.java?rev=574381&r1=574380&r2=574381&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/util/FileUtilsTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/util/FileUtilsTest.java Mon Sep 10
14:38:52 2007
@@ -48,7 +48,10 @@
 
     public void tearDown() {
         if (removeThis != null && removeThis.exists()) {
-            removeThis.delete();
+            if (!removeThis.delete())
+            {
+                removeThis.deleteOnExit();
+            }
         }
     }
 
@@ -333,12 +336,43 @@
         assertEquals(f, new File("a").getAbsoluteFile());
     }
 
+    
     /**
      * Test createTempFile
      */
-    public void testCreateTempFile() {
+    public void testCreateTempFile()
+    {
+    // null parent dir
+    File tmp1 = FILE_UTILS.createTempFile("pre", ".suf", null, false);
+    String  tmploc = System.getProperty("java.io.tmpdir");
+    String 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();
+    
+    File dir2 = new File(tmploc+"/ant-test");
+    dir2.mkdir();
+    removeThis = dir2;
+    
+    File tmp2 = FILE_UTILS.createTempFile("pre", ".suf", dir2, true);
+    String 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();
+    }
+    /**
+     * Test createTempFileName
+     */
+    public void testCreateTempFileName() {
         File parent = new File((new File("/tmp")).getAbsolutePath());
-        File tmp1 = FILE_UTILS.createTempFile("pre", ".suf", parent);
+        File tmp1 = FILE_UTILS.createTempFileName("pre", ".suf", parent, false);
         assertTrue("new file", !tmp1.exists());
 
         String name = tmp1.getName();
@@ -348,12 +382,12 @@
                      parent.getAbsolutePath(),
                      tmp1.getParent());
 
-        File tmp2 = FILE_UTILS.createTempFile("pre", ".suf", parent);
+        File tmp2 = FILE_UTILS.createTempFileName("pre", ".suf", parent, false);
         assertTrue("files are different",
                    !tmp1.getAbsolutePath().equals(tmp2.getAbsolutePath()));
 
         // null parent dir
-        File tmp3 = FILE_UTILS.createTempFile("pre", ".suf", null);
+        File tmp3 = FILE_UTILS.createTempFileName("pre", ".suf", null, false);
         String  tmploc = System.getProperty("java.io.tmpdir");
         assertEquals((new File(tmploc, tmp3.getName())).getAbsolutePath(),
                      tmp3.getAbsolutePath());



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message