Cleanup test indices

Change-Id: I1347a034cbe3464a9eb0380ca68ae200aa9f756e
diff --git a/Changes b/Changes
index c742450..b0448c8 100644
--- a/Changes
+++ b/Changes
@@ -4,6 +4,7 @@
     - [bugfix] Prevent matches in contexts (diewald).
     - [bugfix] Prevent showing empty elements and opening tags past primary data
       (diewald).
+    - [cleanup] Cleanup test generated directories after run (diewald)
 
 0.62.6 2024-06-13
     - [feature] Make match expansion configurable (close #150, margaretha)
diff --git a/src/test/java/de/ids_mannheim/korap/TestIndexer.java b/src/test/java/de/ids_mannheim/korap/TestIndexer.java
index 8f931d5..ee4d1dc 100644
--- a/src/test/java/de/ids_mannheim/korap/TestIndexer.java
+++ b/src/test/java/de/ids_mannheim/korap/TestIndexer.java
@@ -8,6 +8,7 @@
 import java.io.PrintStream;

 

 import org.junit.After;

+import org.junit.AfterClass;

 import org.junit.Before;

 import org.junit.Test;

 import org.slf4j.Logger;

@@ -23,8 +24,9 @@
     private Logger logger = LoggerFactory.getLogger(TestIndexer.class);

     private final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

     private String info = "usage: Krill indexer";

-    private File outputDirectory = new File("test-index");

-    private File outputDirectory2 = new File("test-index2");

+    private static File outputDirectory = new File("test-index");

+    private static File outputDirectory2 = new File("test-index2");

+    private static File outputDirectory3 = new File("test-output");

 

     @Test

     public void testArguments () throws IOException {

@@ -113,27 +115,43 @@
         System.setOut(null);

     }

 

+    @AfterClass

+    public static void cleanup() {

+        if (outputDirectory.exists()) {

+            deleteFile(outputDirectory);

+        }

+        if (outputDirectory2.exists()) {

+            deleteFile(outputDirectory2);

+        }

+        if (outputDirectory3.exists()) {

+            deleteFile(outputDirectory2);

+        }

+    }

+

+    

     @Before

     public void cleanOutputDirectory () {

 

         if (outputDirectory.exists()) {

             logger.debug("Output directory exists");

             deleteFile(outputDirectory);

-            deleteFile(outputDirectory2);

         }

         if (outputDirectory2.exists()) {

             logger.debug("Output directory 2 exists");

             deleteFile(outputDirectory2);

         }

+        if (outputDirectory3.exists()) {

+            logger.debug("Output directory 3 exists");

+            deleteFile(outputDirectory3);

+        }

     }

 

-    private void deleteFile (File path) {

+    private static void deleteFile (File path) {

         if (path.isDirectory()) {

             File file;

             for (String filename : path.list()) {

                 file = new File(path + "/" + filename);

                 deleteFile(file);

-                logger.debug(file.getAbsolutePath());

             }

         }

         path.delete();