1
1
/*
2
- * Copyright 2002-2023 the original author or authors.
2
+ * Copyright 2002-2025 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
18
18
19
19
import java .io .File ;
20
20
21
- import org .junit .jupiter .api .AfterEach ;
22
21
import org .junit .jupiter .api .Test ;
22
+ import org .junit .jupiter .api .io .TempDir ;
23
23
24
24
import static org .assertj .core .api .Assertions .assertThat ;
25
25
26
26
/**
27
+ * Tests for {@link FileSystemUtils}.
28
+ *
27
29
* @author Rob Harrop
30
+ * @author Sam Brannen
28
31
*/
29
32
class FileSystemUtilsTests {
30
33
31
34
@ 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" );
34
37
File child = new File (root , "child" );
35
38
File grandchild = new File (child , "grandchild" );
36
39
@@ -53,8 +56,8 @@ void deleteRecursively() throws Exception {
53
56
}
54
57
55
58
@ 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" );
58
61
File child = new File (src , "child" );
59
62
File grandchild = new File (child , "grandchild" );
60
63
@@ -68,7 +71,7 @@ void copyRecursively() throws Exception {
68
71
assertThat (grandchild ).exists ();
69
72
assertThat (bar ).exists ();
70
73
71
- File dest = new File (". /dest" );
74
+ File dest = new File (tempDir , " /dest" );
72
75
FileSystemUtils .copyRecursively (src , dest );
73
76
74
77
assertThat (dest ).exists ();
@@ -78,17 +81,4 @@ void copyRecursively() throws Exception {
78
81
assertThat (src ).doesNotExist ();
79
82
}
80
83
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
-
94
84
}
0 commit comments