Skip to content

Commit 3301ac8

Browse files
author
Gary Gregory
committed
Revert "Revert "Revert "Use JUnit TempDir instead of custom code."""
This reverts commit d76cf38.
1 parent d76cf38 commit 3301ac8

2 files changed

Lines changed: 25 additions & 4 deletions

File tree

src/test/java/org/apache/commons/io/file/CleaningPathVisitorTest.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,17 @@
1818
package org.apache.commons.io.file;
1919

2020
import static org.apache.commons.io.file.CounterAssertions.assertCounts;
21+
import static org.junit.jupiter.api.Assertions.assertTrue;
2122

2223
import java.io.IOException;
2324
import java.nio.file.Files;
2425
import java.nio.file.Path;
2526
import java.nio.file.Paths;
2627

2728
import org.apache.commons.io.file.Counters.PathCounters;
29+
import org.junit.jupiter.api.AfterEach;
2830
import org.junit.jupiter.api.Assertions;
29-
import org.junit.jupiter.api.io.TempDir;
31+
import org.junit.jupiter.api.BeforeEach;
3032
import org.junit.jupiter.params.ParameterizedTest;
3133
import org.junit.jupiter.params.provider.MethodSource;
3234

@@ -35,14 +37,28 @@
3537
*/
3638
public class CleaningPathVisitorTest extends TestArguments {
3739

38-
@TempDir
3940
private Path tempDir;
4041

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+
4152
private void applyCleanEmptyDirectory(final CleaningPathVisitor visitor) throws IOException {
4253
Files.walkFileTree(tempDir, visitor);
4354
assertCounts(1, 0, 0, visitor);
4455
}
4556

57+
@BeforeEach
58+
public void beforeEach() throws IOException {
59+
tempDir = Files.createTempDirectory(getClass().getCanonicalName());
60+
}
61+
4662
/**
4763
* Tests an empty folder.
4864
*/

src/test/java/org/apache/commons/io/file/CountingPathVisitorTest.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import static org.apache.commons.io.file.CounterAssertions.assertCounts;
2121

2222
import java.io.IOException;
23+
import java.nio.file.Files;
24+
import java.nio.file.Path;
2325

2426
import org.junit.jupiter.api.Assertions;
2527
import org.junit.jupiter.params.ParameterizedTest;
@@ -42,8 +44,11 @@ private void checkZeroCounts(final CountingPathVisitor visitor) {
4244
@MethodSource("countingPathVisitors")
4345
public void testCountEmptyFolder(final CountingPathVisitor visitor) throws IOException {
4446
checkZeroCounts(visitor);
45-
try (final TempDirectory tempDir = TempDirectory.create(getClass().getCanonicalName())) {
46-
assertCounts(1, 0, 0, PathUtils.visitFileTree(visitor, tempDir.unwrap()));
47+
final Path tempDir = Files.createTempDirectory(getClass().getCanonicalName());
48+
try {
49+
assertCounts(1, 0, 0, PathUtils.visitFileTree(visitor, tempDir));
50+
} finally {
51+
Files.deleteIfExists(tempDir);
4752
}
4853
}
4954

0 commit comments

Comments
 (0)