|
18 | 18 | package org.apache.commons.io.file; |
19 | 19 |
|
20 | 20 | import static org.apache.commons.io.file.CounterAssertions.assertCounts; |
| 21 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
21 | 22 |
|
22 | 23 | import java.io.IOException; |
23 | 24 | import java.nio.file.Files; |
24 | 25 | import java.nio.file.Path; |
25 | 26 | import java.nio.file.Paths; |
26 | 27 |
|
27 | 28 | import org.apache.commons.io.file.Counters.PathCounters; |
| 29 | +import org.junit.jupiter.api.AfterEach; |
28 | 30 | import org.junit.jupiter.api.Assertions; |
29 | | -import org.junit.jupiter.api.io.TempDir; |
| 31 | +import org.junit.jupiter.api.BeforeEach; |
30 | 32 | import org.junit.jupiter.params.ParameterizedTest; |
31 | 33 | import org.junit.jupiter.params.provider.MethodSource; |
32 | 34 |
|
|
35 | 37 | */ |
36 | 38 | public class CleaningPathVisitorTest extends TestArguments { |
37 | 39 |
|
38 | | - @TempDir |
39 | 40 | private Path tempDir; |
40 | 41 |
|
| 42 | + @AfterEach |
| 43 | + public void afterEach() throws IOException { |
| 44 | + // temp dir should still exist since we are cleaning and not deleting. |
| 45 | + assertTrue(Files.exists(tempDir)); |
| 46 | + // backstop |
| 47 | + if (Files.exists(tempDir) && PathUtils.isEmptyDirectory(tempDir)) { |
| 48 | + Files.deleteIfExists(tempDir); |
| 49 | + } |
| 50 | + } |
| 51 | + |
41 | 52 | private void applyCleanEmptyDirectory(final CleaningPathVisitor visitor) throws IOException { |
42 | 53 | Files.walkFileTree(tempDir, visitor); |
43 | 54 | assertCounts(1, 0, 0, visitor); |
44 | 55 | } |
45 | 56 |
|
| 57 | + @BeforeEach |
| 58 | + public void beforeEach() throws IOException { |
| 59 | + tempDir = Files.createTempDirectory(getClass().getCanonicalName()); |
| 60 | + } |
| 61 | + |
46 | 62 | /** |
47 | 63 | * Tests an empty folder. |
48 | 64 | */ |
|
0 commit comments