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 30da27f..ab44bb3 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();
+        }
+    }
+
 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.