Add test testForceDeleteReadOnlyFile.
MODIFY
src/test/java/org/apache/commons/io/FileUtilsTestCase.java
src/test/java/org/apache/commons/io/FileUtilsTestCase.java
@@ -1464,6 +1464,24 @@ public void testForceDeleteDir() throws Exception {
assertFalse(testDirectory.exists(), "TestDirectory must not exist");
}
+ @Test
+ public void testForceDeleteReadOnlyFile() throws Exception {
+ File destination = File.createTempFile("test-", ".txt");
+ assertTrue(destination.setReadOnly());
+ assertTrue(destination.canRead());
+ assertFalse(destination.canWrite());
+ // sanity check
+ assertTrue(destination.delete());
+ destination = File.createTempFile("test-", ".txt");
+ // real test
+ assertTrue(destination.setReadOnly());
+ assertTrue(destination.canRead());
+ assertFalse(destination.canWrite());
+ assertTrue(destination.exists(), "File doesn't exist to delete");
+ FileUtils.forceDelete(destination);
+ assertTrue(!destination.exists(), "Check deletion");
+ }
+
@Test
public void testForceMkdir() throws Exception {
// Tests with existing directory

Add test testForceDeleteReadOnlyFile.