svn commit: r18026 - trunk/src/argouml-app/tests/org/argouml/FileHelper.java
Linus Tolke <[email protected]>
| Newsgroups | gmane.comp.lang.uml.argouml.cvs |
|---|---|
| Message-ID | <[email protected]> |
Author: linus
Date: 2010-02-20 03:45:49-0800
New Revision: 18026
Modified:
trunk/src/argouml-app/tests/org/argouml/FileHelper.java
Log:
Fixed the failing test case.
Added more checks of the file operations.
Added removal of the test files after completion.
Modified: trunk/src/argouml-app/tests/org/argouml/FileHelper.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-app/tests/org/argouml/FileHelper.java?view=diff&pathrev=18026&r1=18025&r2=18026
==============================================================================
--- trunk/src/argouml-app/tests/org/argouml/FileHelper.java (original)
+++ trunk/src/argouml-app/tests/org/argouml/FileHelper.java 2010-02-20 03:45:49-0800
@@ -8,6 +8,7 @@
*
* Contributors:
* euluis
+ * linus
*****************************************************************************
*
* Some portions of this file was previously release using the BSD License:
@@ -41,8 +42,6 @@
import java.io.File;
import java.io.IOException;
-import junit.framework.TestCase;
-
/**
* Helper for common File related operations used in automated tests.
*
@@ -68,8 +67,8 @@
}
/**
- * @param testClass the {@link TestCase} class for which to create a
- * directory.
+ * @param testClass the {@link junit.framework.TestCase} class for
+ * which to create a directory.
* @return the created directory.
* @throws IOException if the directory creation fails.
*/
@@ -106,8 +105,13 @@
public static File createTempDirectory(String prefix) throws IOException {
File tempFile = File.createTempFile(prefix, "");
String absolutePath = tempFile.getAbsolutePath();
- tempFile.delete();
- tempFile.mkdir();
+ if (tempFile.exists()) {
+ boolean deleted = tempFile.delete();
+ assert deleted : "Deletion of " + tempFile + " failed.";
+ }
+ boolean created = tempFile.mkdir();
+ assert created : "Creation of directory " + tempFile + " failed.";
+ tempFile.deleteOnExit();
return new File(absolutePath);
}
@@ -131,16 +135,20 @@
* NOTE: should contain "." if it is intended to be an extension.
* @param directoryPrefix the prefix of the new directory name.
* @return the new {@link File}.
- * @throws IOException
+ * @throws IOException if any of the file operation throws it.
*/
public static File moveFileToNewTempDirectory(File fileToMove,
String filePrefix, String fileSuffix, String directoryPrefix)
- throws IOException {
+ throws IOException {
File directory = createTempDirectory(directoryPrefix);
File newFile = File.createTempFile(filePrefix, fileSuffix, directory);
+ boolean deleted = newFile.delete();
+ assert deleted
+ : "Deletion of newly created file " + newFile + "failed.";
boolean renamed = fileToMove.renameTo(newFile);
- assert renamed : "Renaming of " + fileToMove + " to "
- + newFile + " failed.";
+ assert renamed
+ : "Renaming of " + fileToMove + " to " + newFile + " failed.";
+ newFile.deleteOnExit();
return newFile;
}
}
------------------------------------------------------
http://argouml.tigris.org/ds/viewMessage.do?dsForumId=5905&dsMessageId=2449535
To unsubscribe from this discussion, e-mail: [[email protected]].