BUG 2839: Config: remove dependencies on commons-io
[controller.git] / opendaylight / config / config-manager / src / test / java / org / opendaylight / controller / config / manager / impl / AbstractConfigTest.java
index 30da27f1a1dee6951d05fe59b96b81e319d936c6..ab44bb34958da1d22fed964b8ed701a2a7427c24 100644 (file)
@@ -14,6 +14,8 @@ import static org.mockito.Mockito.doNothing;
 import static org.mockito.Mockito.mock;
 
 import com.google.common.base.Preconditions;
+import java.io.File;
+import java.io.IOException;
 import java.lang.management.ManagementFactory;
 import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.InvocationTargetException;
@@ -288,4 +290,27 @@ public abstract class AbstractConfigTest extends
         return (T) proxy;
     }
 
+    /**
+     * removes contents of the directory
+     * @param dir to be cleaned
+     * @throws IOException
+     */
+    protected void cleanDirectory(File dir) throws IOException {
+        if (!dir.isDirectory()) {
+            throw new IllegalStateException("dir must be a directory");
+        }
+
+        final File[] files = dir.listFiles();
+        if (files == null) {
+            throw new IOException("Failed to list contents of " + dir);
+        }
+
+        for (File file : files) {
+            if (file.isDirectory()) {
+                cleanDirectory(dir);
+            }
+            file.delete();
+        }
+    }
+
 }