11package pl .wavesoftware .testing ;
22
3+ import com .google .common .io .Files ;
4+ import java .io .File ;
35import org .junit .Test ;
46import org .junit .rules .TestRule ;
57import org .junit .runner .Description ;
911import java .lang .reflect .Method ;
1012import java .lang .reflect .Modifier ;
1113import 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 ;
1815
1916/**
2017 * @author <a href="mailto:krzysztof.suszynski@coi.gov.pl">Krzysztof Suszynski</a>
@@ -47,7 +44,6 @@ private Class<?> validateTestClass(Class<?> testClass) {
4744
4845 @ Override
4946 public Statement apply (final Statement base , Description description ) {
50-
5147 return new Statement () {
5248 @ Override
5349 public void evaluate () throws Throwable {
@@ -62,22 +58,19 @@ public void evaluate() throws Throwable {
6258
6359 private void cleanup () throws IOException , URISyntaxException {
6460 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 ()) {
6764 return ;
6865 }
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 ());
8275 }
8376}
0 commit comments