OSDN Git Service

test complete: DeleteDir.java
authorhayashi <hayashi.yuu@gmail.com>
Thu, 18 May 2017 12:22:24 +0000 (21:22 +0900)
committerhayashi <hayashi.yuu@gmail.com>
Thu, 18 May 2017 12:22:24 +0000 (21:22 +0900)
test/hayashi/tools/files/DeleteDirTest.java

index e63abb0..978544d 100644 (file)
@@ -11,7 +11,11 @@ public class DeleteDirTest {
 
        @Test(expected = IOException.class)
        public void 指定したファイルがないとき() throws Exception {
-               DeleteDir.delete(new File("testspace", "FOLDER"));
+               File dir = new File("testspace", "FOLDER");
+               if (dir.exists()) {
+                       DeleteDir.delete(dir);
+               }
+               DeleteDir.delete(dir);
                fail("例外が発生しない");               // 例外が発生しなければ失敗
        }
        
@@ -22,4 +26,23 @@ public class DeleteDirTest {
                DeleteDir.delete(new File("testspace", "FILE"));
                assertThat(newfile.exists(), is(false));
        }
+
+       @Test
+       public void 削除対象が空のフォルダのとき() throws IOException {
+               File newdir = new File("testspace", "FOLDER");
+               newdir.mkdirs();
+               DeleteDir.delete(new File("testspace", "FOLDER"));
+               assertThat(newdir.exists(), is(false));
+       }
+
+       @Test
+       public void 削除対象がNEXTしたフォルダのとき() throws IOException {
+               File newdir = new File("testspace", "FOLDER");
+               newdir.mkdirs();
+               (new File("testspace/FOLDER", "FOLDER")).mkdir();
+               (new File("testspace/FOLDER", "FILE")).createNewFile();
+               (new File("testspace/FOLDER/FOLDER", "FILE")).createNewFile();
+               DeleteDir.delete(new File("testspace", "FOLDER"));
+               assertThat(newdir.exists(), is(false));
+       }
 }