Skip to content

Commit 9dc9e59

Browse files
committed
[IO-857"][Javadoc] PathUtils.cleanDirectory() methods vs FileUtils.
Add FileUtils test assertions
1 parent 5fe2056 commit 9dc9e59

2 files changed

Lines changed: 10 additions & 15 deletions

File tree

src/test/java/org/apache/commons/io/FileUtilsCleanDirectoryTest.java

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -68,66 +68,57 @@ private boolean chmod(final File file, final int mode, final boolean recurse) th
6868
void testCleanDirectoryToForceDelete() throws Exception {
6969
final File file = new File(tempDirFile, "restricted");
7070
FileUtils.touch(file);
71-
7271
// 300 = owner: WE.
7372
// 500 = owner: RE.
7473
// 700 = owner: RWE.
7574
assumeTrue(chmod(tempDirFile, 700, false));
76-
7775
// cleanDirectory calls forceDelete
7876
FileUtils.cleanDirectory(tempDirFile);
77+
assertTrue(tempDirFile.exists());
7978
}
8079

8180
@Test
8281
void testCleanEmpty() throws Exception {
8382
assertEquals(0, tempDirFile.list().length);
84-
8583
FileUtils.cleanDirectory(tempDirFile);
86-
84+
assertTrue(tempDirFile.exists());
8785
assertEquals(0, tempDirFile.list().length);
8886
}
8987

9088
@Test
9189
void testDeletesNested() throws Exception {
9290
final File nested = new File(tempDirFile, "nested");
93-
9491
assertTrue(nested.mkdirs());
95-
9692
FileUtils.touch(new File(nested, "file"));
97-
9893
assertEquals(1, tempDirFile.list().length);
99-
10094
FileUtils.cleanDirectory(tempDirFile);
101-
95+
assertTrue(tempDirFile.exists());
10296
assertEquals(0, tempDirFile.list().length);
10397
}
10498

10599
@Test
106100
void testDeletesRegular() throws Exception {
107101
FileUtils.touch(new File(tempDirFile, "regular"));
108102
FileUtils.touch(new File(tempDirFile, ".hidden"));
109-
110103
assertEquals(2, tempDirFile.list().length);
111-
112104
FileUtils.cleanDirectory(tempDirFile);
113-
105+
assertTrue(tempDirFile.exists());
114106
assertEquals(0, tempDirFile.list().length);
115107
}
116108

117109
@DisabledOnOs(OS.WINDOWS)
118110
@Test
119111
void testThrowsOnNullList() throws Exception {
120-
// test won't work if we can't restrict permissions on the
121-
// directory, so skip it.
112+
// test won't work if we can't restrict permissions on the directory, so skip it.
122113
assumeTrue(chmod(tempDirFile, 0, false));
123-
124114
try {
125115
// cleanDirectory calls forceDelete
126116
final IOException e = assertThrows(IOException.class, () -> FileUtils.cleanDirectory(tempDirFile));
127117
assertEquals("Unknown I/O error listing contents of directory: " + tempDirFile.getAbsolutePath(), e.getMessage());
128118
} finally {
129119
chmod(tempDirFile, 755, false);
130120
}
121+
assertTrue(tempDirFile.exists());
131122
}
132123

133124
}

src/test/java/org/apache/commons/io/FileUtilsCleanSymlinksTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ void testCleanDirWithASymlinkDir() throws Exception {
8282

8383
// assert contents of the real directory were removed including the symlink
8484
FileUtils.cleanDirectory(realOuter);
85+
assertTrue(realOuter.exists());
8586
assertEquals(0, realOuter.list().length);
8687

8788
// ensure that the contents of the symlink were NOT removed.
@@ -121,6 +122,7 @@ void testCleanDirWithParentSymlinks() throws Exception {
121122
// assert contents of the real directory were removed including the symlink
122123
// should clean the contents of this but not recurse into other links
123124
FileUtils.cleanDirectory(symlinkParentDirectory);
125+
assertTrue(symlinkParentDirectory.exists());
124126
assertEquals(0, symlinkParentDirectory.list().length);
125127
assertEquals(0, realParent.list().length);
126128

@@ -155,6 +157,7 @@ void testCleanDirWithSymlinkFile() throws Exception {
155157

156158
// assert contents of the real directory were removed including the symlink
157159
FileUtils.cleanDirectory(realOuter);
160+
assertTrue(realOuter.exists());
158161
assertEquals(0, realOuter.list().length);
159162

160163
// ensure that the contents of the symlink were NOT removed.
@@ -256,6 +259,7 @@ void testStillClearsIfGivenDirectoryIsASymlink() throws Exception {
256259
assertTrue(setupSymlink(randomDirectory, symlinkDirectory));
257260

258261
FileUtils.cleanDirectory(symlinkDirectory);
262+
assertTrue(symlinkDirectory.exists());
259263
assertEquals(0, symlinkDirectory.list().length);
260264
assertEquals(0, randomDirectory.list().length);
261265
}

0 commit comments

Comments
 (0)