• R/O
  • HTTP
  • SSH
  • HTTPS

hayashi: Commit

hayashi lib.
java


Commit MetaInfo

Revisióndbf0e4051300274061c60e73fefe1e2f1120e317 (tree)
Tiempo2017-05-18 19:56:38
Autorhayashi <hayashi.yuu@gmai...>
Commiterhayashi

Log Message

testcase: DeleteDirTest

Cambiar Resumen

Diferencia incremental

--- a/src/hayashi/tools/files/DeleteDir.java
+++ b/src/hayashi/tools/files/DeleteDir.java
@@ -22,7 +22,7 @@ public class DeleteDir
2222 }
2323
2424 try {
25- DeleteDir.listup(new File(args[0]));
25+ DeleteDir.delete(new File(args[0]));
2626 }
2727 catch(Exception e) {
2828 e.printStackTrace();
@@ -30,17 +30,17 @@ public class DeleteDir
3030 }
3131 }
3232
33- public static void listup(File file) throws IOException {
33+ public static void delete(File file) throws IOException {
3434 if (!file.exists()) {
3535 System.out.println("ERROR: ファイルまたはディレクトリが見つかりませんでした。");
36- return;
36+ throw new IOException("File not found.");
3737 }
3838
3939 if (file.isDirectory()) {
4040 File files[] = file.listFiles();
4141 if (files != null) {
4242 for (int i=0; i < files.length; i++) {
43- listup(files[i]); // 再帰呼び出し
43+ delete(files[i]); // 再帰呼び出し
4444 }
4545 }
4646 }
--- a/test/hayashi/tools/files/DeleteDirTest.java
+++ b/test/hayashi/tools/files/DeleteDirTest.java
@@ -1,15 +1,25 @@
11 package hayashi.tools.files;
22
33 import java.io.File;
4+import java.io.IOException;
45
6+import static org.hamcrest.CoreMatchers.is;
7+import static org.junit.Assert.*;
58 import org.junit.Test;
69
7-import junit.framework.TestCase;
10+public class DeleteDirTest {
811
9-public class DeleteDirTest extends TestCase {
10-
11- @Test(expected = Exception.class)
12+ @Test(expected = IOException.class)
1213 public void 指定したファイルがないとき() throws Exception {
13- DeleteDir.listup(new File("testspace", "FOLDER"));
14+ DeleteDir.delete(new File("testspace", "FOLDER"));
15+ fail("例外が発生しない"); // 例外が発生しなければ失敗
16+ }
17+
18+ @Test
19+ public void 削除対象がファイルのとき() throws IOException {
20+ File newfile = new File("testspace", "FILE");
21+ newfile.createNewFile();
22+ DeleteDir.delete(new File("testspace", "FILE"));
23+ assertThat(newfile.exists(), is(false));
1424 }
1525 }
Show on old repository browser