Skip to content

Commit 7a6f9bd

Browse files
committed
Use @⁠TempDir in FileSystemUtilsTests
1 parent 6c27dbc commit 7a6f9bd

File tree

1 file changed

+10
-20
lines changed

1 file changed

+10
-20
lines changed

spring-core/src/test/java/org/springframework/util/FileSystemUtilsTests.java

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,19 +18,22 @@
1818

1919
import java.io.File;
2020

21-
import org.junit.jupiter.api.AfterEach;
2221
import org.junit.jupiter.api.Test;
22+
import org.junit.jupiter.api.io.TempDir;
2323

2424
import static org.assertj.core.api.Assertions.assertThat;
2525

2626
/**
27+
* Tests for {@link FileSystemUtils}.
28+
*
2729
* @author Rob Harrop
30+
* @author Sam Brannen
2831
*/
2932
class FileSystemUtilsTests {
3033

3134
@Test
32-
void deleteRecursively() throws Exception {
33-
File root = new File("./tmp/root");
35+
void deleteRecursively(@TempDir File tempDir) throws Exception {
36+
File root = new File(tempDir, "root");
3437
File child = new File(root, "child");
3538
File grandchild = new File(child, "grandchild");
3639

@@ -53,8 +56,8 @@ void deleteRecursively() throws Exception {
5356
}
5457

5558
@Test
56-
void copyRecursively() throws Exception {
57-
File src = new File("./tmp/src");
59+
void copyRecursively(@TempDir File tempDir) throws Exception {
60+
File src = new File(tempDir, "src");
5861
File child = new File(src, "child");
5962
File grandchild = new File(child, "grandchild");
6063

@@ -68,7 +71,7 @@ void copyRecursively() throws Exception {
6871
assertThat(grandchild).exists();
6972
assertThat(bar).exists();
7073

71-
File dest = new File("./dest");
74+
File dest = new File(tempDir, "/dest");
7275
FileSystemUtils.copyRecursively(src, dest);
7376

7477
assertThat(dest).exists();
@@ -78,17 +81,4 @@ void copyRecursively() throws Exception {
7881
assertThat(src).doesNotExist();
7982
}
8083

81-
82-
@AfterEach
83-
void tearDown() {
84-
File tmp = new File("./tmp");
85-
if (tmp.exists()) {
86-
FileSystemUtils.deleteRecursively(tmp);
87-
}
88-
File dest = new File("./dest");
89-
if (dest.exists()) {
90-
FileSystemUtils.deleteRecursively(dest);
91-
}
92-
}
93-
9484
}

0 commit comments

Comments
 (0)