OSDN Git Service

WayBackTimeParserリファクタリングのためのコメント、テストケース追加
authoryukihane <yukihane.feather@gmail.com>
Thu, 18 Aug 2011 22:57:51 +0000 (07:57 +0900)
committeryukihane <yukihane.feather@gmail.com>
Thu, 18 Aug 2011 22:57:51 +0000 (07:57 +0900)
frontend/src/saccubus/util/WayBackTimeParser.java
frontend/test/saccubus/util/WayBackTimeParserTest.java [new file with mode: 0644]

index b08c9f9..aa1a696 100644 (file)
@@ -7,7 +7,7 @@ import java.text.SimpleDateFormat;
 import java.util.Date;
 
 /**
- *
+ * 過去ログ取得時に指定する文字列(日付)をパースするユーティリティクラスです.
  * @author yuki
  */
 public final class WayBackTimeParser {
@@ -15,9 +15,17 @@ public final class WayBackTimeParser {
     private WayBackTimeParser() {
     }
 
+    /**
+     * 過去の時点を指定する文字列から、コメント取得フォーマットの"when"に指定する文字列へ変換します.
+     * この文字列は、1970 年 1 月 1 日 00:00:00 GMT からの秒数(一般的なミリ秒ではない)になります.
+     * @param time 時点指定文字列。"YYYY/MM/DD hh:mm:ss", "YYYY/MM/DD hh:mm", 秒数を表す数値,
+     * のいずれかであればパース可能です.
+     * @return パース結果.
+     * @throws IOException パース失敗.
+     */
     public static String parse(String time) throws IOException {
         Date date = null;
-        String waybacktime = "0";
+        String waybacktime;
         try {
             final DateFormat fmt = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
             date = fmt.parse(time);
diff --git a/frontend/test/saccubus/util/WayBackTimeParserTest.java b/frontend/test/saccubus/util/WayBackTimeParserTest.java
new file mode 100644 (file)
index 0000000..69874e0
--- /dev/null
@@ -0,0 +1,38 @@
+package saccubus.util;
+
+import java.io.IOException;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+/**
+ *
+ * @author yuki
+ */
+public class WayBackTimeParserTest {
+
+    /** 年月日時分秒指定 */
+    @Test
+    public void testParseYYYYMMDD_H_M_S() throws IOException {
+        final String text = "2011/08/19 00:00:12";
+        final String expected = "1313679612";
+        final String actual = WayBackTimeParser.parse(text);
+        assertEquals(expected, actual);
+    }
+
+    /** 年月日時分指定(秒省略) */
+    @Test
+    public void testParseYYYYMMDD_H_M() throws IOException {
+        final String text = "2011/08/19 00:00";
+        final String expected = "1313679600";
+        final String actual = WayBackTimeParser.parse(text);
+        assertEquals(expected, actual);
+    }
+
+    /** 1970 年 1 月 1 日 00:00:00 GMT からの秒数指定(一般的なミリ秒指定ではないことに注意 */
+    @Test
+    public void testParseNumber() throws IOException {
+        final String text = "1313679600";
+        final String actual = WayBackTimeParser.parse(text);
+        assertEquals(text, actual);
+    }
+}