1
1
package pl .wavesoftware .testing ;
2
2
3
+ import com .google .common .io .Files ;
4
+ import java .io .File ;
3
5
import org .junit .Test ;
4
6
import org .junit .rules .TestRule ;
5
7
import org .junit .runner .Description ;
9
11
import java .lang .reflect .Method ;
10
12
import java .lang .reflect .Modifier ;
11
13
import java .net .URISyntaxException ;
12
- import java .nio .file .FileVisitResult ;
13
- import java .nio .file .Files ;
14
- import java .nio .file .Path ;
15
- import java .nio .file .Paths ;
16
- import java .nio .file .SimpleFileVisitor ;
17
- import java .nio .file .attribute .BasicFileAttributes ;
14
+ import org .apache .commons .io .FileUtils ;
18
15
19
16
/**
20
17
* @author <a href="mailto:[email protected] ">Krzysztof Suszynski</a>
@@ -47,7 +44,6 @@ private Class<?> validateTestClass(Class<?> testClass) {
47
44
48
45
@ Override
49
46
public Statement apply (final Statement base , Description description ) {
50
-
51
47
return new Statement () {
52
48
@ Override
53
49
public void evaluate () throws Throwable {
@@ -62,22 +58,19 @@ public void evaluate() throws Throwable {
62
58
63
59
private void cleanup () throws IOException , URISyntaxException {
64
60
String location = testClass .getProtectionDomain ().getCodeSource ().getLocation ().toURI ().getPath ();
65
- Path testAnnotationsPath = Paths .get (location ).getParent ().resolve (GENERATED_TEST_SOURCES ).resolve (TEST_ANNOTATIONS );
66
- if (!testAnnotationsPath .toFile ().isDirectory ()) {
61
+ File file = new File (location ).getCanonicalFile ().getParentFile ();
62
+ File testAnnotationsPath = resolve (file , GENERATED_TEST_SOURCES , TEST_ANNOTATIONS );
63
+ if (!testAnnotationsPath .isDirectory ()) {
67
64
return ;
68
65
}
69
- Files .walkFileTree (testAnnotationsPath , new SimpleFileVisitor <Path >() {
70
- @ Override
71
- public FileVisitResult visitFile (Path file , BasicFileAttributes attrs ) throws IOException {
72
- Files .delete (file );
73
- return FileVisitResult .CONTINUE ;
74
- }
75
-
76
- @ Override
77
- public FileVisitResult postVisitDirectory (Path dir , IOException exc ) throws IOException {
78
- Files .delete (dir );
79
- return FileVisitResult .CONTINUE ;
80
- }
81
- });
66
+ FileUtils .deleteDirectory (testAnnotationsPath );
67
+ }
68
+
69
+ private File resolve (File parent , String ... paths ) {
70
+ StringBuilder sb = new StringBuilder (parent .getPath ());
71
+ for (String path : paths ) {
72
+ sb .append (File .separator ).append (path );
73
+ }
74
+ return new File (sb .toString ());
82
75
}
83
76
}
0 commit comments