Skip to content

Commit

Permalink
[IO-856] Add FileUtilsListFilesTest.testListFilesWithDeletion()
Browse files Browse the repository at this point in the history
This test passes for me locally using:
- Windows 10: Microsoft Windows [Version 10.0.19045.4412]
- WSL Linux ---- 5.15.133.1-microsoft-standard-WSL2 #1 SMP Thu Oct 5
21:02:42 UTC 2023 x86_64 x86_64 x86_64 GNU/
  • Loading branch information
garydgregory committed Jun 6, 2024
1 parent 6bace53 commit 97c4803
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/test/java/org/apache/commons/io/FileUtilsListFilesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,17 @@
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.apache.commons.io.filefilter.FileFilterUtils;
import org.apache.commons.io.filefilter.IOFileFilter;
import org.apache.commons.io.function.Uncheck;
import org.apache.commons.lang3.function.Consumers;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -202,4 +206,20 @@ public void testListFilesByExtension() {
assertFalse(fileNames.contains("dummy-file.txt"));
}

@Test
public void testListFilesWithDeletion() throws IOException {
final String[] extensions = {"xml", "txt"};
final List<File> list;
final File xFile = new File(temporaryFolder, "x.xml");
xFile.createNewFile();
final Collection<File> files = FileUtils.listFiles(temporaryFolder, extensions, true);
assertEquals(5, files.size());
try (Stream<File> stream = Uncheck.get(() -> FileUtils.streamFiles(temporaryFolder, true, extensions))) {
assertTrue(xFile.delete());
list = stream.collect(Collectors.toList());
assertFalse(list.contains(xFile), list::toString);
}
assertEquals(4, list.size());
}

}

0 comments on commit 97c4803

Please sign in to comment.