OSDN Git Service

2019-02-11
[hayashilib/hayashi.git] / test / hayashi / tools / files / DeleteDirTest.java
1 package hayashi.tools.files;
2
3 import java.io.File;
4 import java.io.IOException;
5
6 import static org.hamcrest.CoreMatchers.is;
7 import static org.junit.Assert.*;
8
9 import org.junit.Test;
10
11 public class DeleteDirTest {
12
13         @Test(expected = IOException.class)
14         public void 指定したファイルがないとき() throws Exception {
15                 File dir = new File("testspace", "FOLDER");
16                 if (dir.exists()) {
17                         DeleteDir.delete(dir);
18                 }
19                 DeleteDir.delete(dir);
20                 fail("例外が発生しない");               // 例外が発生しなければ失敗
21         }
22         
23         @Test
24         public void 削除対象がファイルのとき() throws IOException {
25                 File newfile = new File("testspace", "FILE");
26                 newfile.createNewFile();
27                 DeleteDir.delete(new File("testspace", "FILE"));
28                 assertThat(newfile.exists(), is(false));
29         }
30
31         @Test
32         public void 削除対象が空のフォルダのとき() throws IOException {
33                 File newdir = new File("testspace", "FOLDER");
34                 newdir.mkdirs();
35                 DeleteDir.delete(new File("testspace", "FOLDER"));
36                 assertThat(newdir.exists(), is(false));
37         }
38
39         @Test
40         public void 削除対象がNEXTしたフォルダのとき() throws IOException {
41                 File newdir = new File("testspace", "FOLDER");
42                 newdir.mkdirs();
43                 (new File("testspace/FOLDER", "FOLDER")).mkdir();
44                 (new File("testspace/FOLDER", "FILE")).createNewFile();
45                 (new File("testspace/FOLDER/FOLDER", "FILE")).createNewFile();
46                 DeleteDir.delete(new File("testspace", "FOLDER"));
47                 assertThat(newdir.exists(), is(false));
48         }
49 }