Author: scolebourne Date: Sat Oct 7 06:47:06 2006 New Revision: 453903 URL: http://svn.apache.org/viewvc?view=rev&rev=453903 Log: Add tests for FileDeleteStrategy
Modified: jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/FileDeleteStrategy.java jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/PackageTestSuite.java Modified: jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/FileDeleteStrategy.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/FileDeleteStrategy.java?view=diff&rev=453903&r1=453902&r2=453903 ============================================================================== --- jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/FileDeleteStrategy.java (original) +++ jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/FileDeleteStrategy.java Sat Oct 7 06:47:06 2006 @@ -29,7 +29,7 @@ * This class captures the strategy to use and is designed for user subclassing. * * @author Stephen Colebourne - * @version $Id: $ + * @version $Id$ * @since Commons IO 1.3 */ public class FileDeleteStrategy { @@ -70,7 +70,7 @@ * @return true if the file was deleted, or there was no such file */ public boolean deleteQuietly(File fileToDelete) { - if (fileToDelete == null) { + if (fileToDelete == null || fileToDelete.exists() == false) { return true; } try { @@ -91,7 +91,7 @@ * @throws IOException if an error occurs during file deletion */ public void delete(File fileToDelete) throws IOException { - if (doDelete(fileToDelete) == false) { + if (fileToDelete.exists() && doDelete(fileToDelete) == false) { throw new IOException("Deletion failed: " + fileToDelete); } } @@ -103,12 +103,12 @@ * The implementation may return either false or an <code>IOException</code> * when deletion fails. The [EMAIL PROTECTED] #delete(File)} and [EMAIL PROTECTED] #deleteQuietly(File)} * methods will handle either response appropriately. - * If the file does not exist, the implementation must return true. + * A check has been made to ensure that the file will exist. * <p> * This implementation uses [EMAIL PROTECTED] File#delete()}. * - * @param fileToDelete the file to delete, not null - * @return true if the file was deleted, or there was no such file + * @param fileToDelete the file to delete, exists, not null + * @return true if the file was deleteds * @throws NullPointerException if the file is null * @throws IOException if an error occurs during file deletion */ @@ -123,7 +123,7 @@ * @return a string describing the delete strategy */ public String toString() { - return "FileDelete[" + name + "]"; + return "FileDeleteStrategy[" + name + "]"; } //----------------------------------------------------------------------- @@ -148,9 +148,7 @@ * @throws IOException if an error occurs during file deletion */ protected boolean doDelete(File fileToDelete) throws IOException { - if (fileToDelete.exists()) { - FileUtils.forceDelete(fileToDelete); - } + FileUtils.forceDelete(fileToDelete); return true; } } Modified: jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/PackageTestSuite.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/PackageTestSuite.java?view=diff&rev=453903&r1=453902&r2=453903 ============================================================================== --- jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/PackageTestSuite.java (original) +++ jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/PackageTestSuite.java Sat Oct 7 06:47:06 2006 @@ -39,6 +39,7 @@ suite.addTest(new TestSuite(DemuxTestCase.class)); suite.addTest(new TestSuite(EndianUtilsTest.class)); suite.addTest(new TestSuite(FileCleanerTestCase.class)); + suite.addTest(new TestSuite(FileDeleteStrategyTestCase.class)); suite.addTest(new TestSuite(FilenameUtilsTestCase.class)); suite.addTest(new TestSuite(FilenameUtilsWildcardTestCase.class)); suite.addTest(new TestSuite(FileSystemUtilsTestCase.class)); --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]