Merge branch 'feature/craete_test' into develop
add .travis.yml
Merge branch 'feature/travis-ci' into develop
add Build Status into README
Merge branch 'feature/travis-ci' into develop
Merge branch 'develop' into feature/craete_test
[from now] 2012年 9月 22日 土曜日 20:39:43 JST

diff --git a/core/src/main/scala/webservice/response/ichiba/AsurakuStatus.scala b/core/src/main/scala/webservice/response/ichiba/AsurakuStatus.scala
index 1f36036..9a06c50 100644
--- a/core/src/main/scala/webservice/response/ichiba/AsurakuStatus.scala
+++ b/core/src/main/scala/webservice/response/ichiba/AsurakuStatus.scala
@@ -25,8 +25,10 @@ object AsurakuStatus {

   def parseAreasVld(str: String): Validation[ApiError, List[AsurakuArea]] =
     str
+      .replaceAllLiterally("/", "/#")
       .split('/')
       .toList
+      .map(_.replaceFirst("^#", ""))
       .map(AsurakuArea.parseOpt)
       .sequence[Option, AsurakuArea]
       .toSuccess(JsonParseError("asurakuArea can't be parsed"))
diff --git a/core/src/test/scala/webservice/response/ichiba/AsurakuStatusSpec.scala b/core/src/test/scala/webservice/response/ichiba/AsurakuStatusSpec.scala
new file mode 100644
index 0000000..ffde2e9
--- /dev/null
+++ b/core/src/test/scala/webservice/response/ichiba/AsurakuStatusSpec.scala
@@ -0,0 +1,108 @@
+package jp.co.rakuten.webservice
+
+import org.specs2._, matcher.DataTables
+import scalaz._, Scalaz._
+import org.scala_tools.time.Imports._
+
+class AsurakuStatusSpec extends Specification with DataTables { def is =
+
+  "AsurakuStatsu"                                                                                   ^
+    "parseClosingTimeVld"                                                                           ^
+      """"HH:MM"の形式の文字列に対し、その時刻を表すLocalTimeをsuccessで返す"""                     ! e1^
+      """"HH:MM"の形式でない場合、JsonParseErrorをfailureで返す"""                                  ! e2^
+                                                                                                    p^
+    "parseAreasVld"                                                                                 ^
+      "「/」区切りのあす楽エリア文字列に対し、そのparse結果をList[AsurakuArea]のsuccessで返す"      ! e3^
+      ("空文字の場合や、「/」による分割後に不正な文字列が1つでもある場合" +
+         "、JsonParseErrorをfailureで返す")                                                         ! e4^
+                                                                                                    p^
+    "parseVld"                                                                                      ^
+      "flag = 0の場合はDisableAsurakuをsuccessで返す"                                               ! e5^
+      "flag = 1で、closingTime,areasのparseに成功した場合はAccesptAsurakuをsuccessで返す"           ! e6^
+      "flag = 1で、closingTime,areasいずれかのparseに失敗した場合はJsonParseErrorをfailureで返す"   ! e7^
+      "flagが0,1以外の場合はJsonParseErrorをfailureで返す"                                          ! e8^
+                                                                                                    end
+
+  def e1 =
+    "input" || "result"              |
+    "00:00" !! new LocalTime(0, 0)   |
+    "03:07" !! new LocalTime(3, 7)   |
+    "11:23" !! new LocalTime(11, 23) |
+    "18:09" !! new LocalTime(18, 9)  |
+    "23:59" !! new LocalTime(23, 59) |> { (input, result) =>
+      AsurakuStatus.parseClosingTimeVld(input) must equalTo(result.success)
+    }
+
+  def e2 =
+    "input"  || "result"  |
+    "abc"    !! "failure" |
+    "日本語" !! "failure" |
+    "1234"   !! "failure" |
+    "1:234"  !! "failure" |
+    "123:4"  !! "failure" |
+    "24:00"  !! "failure" |> { (input, _) =>
+      AsurakuStatus.parseClosingTimeVld(input).toEither must beLeft.like {
+        case JsonParseError(_) => ok
+      }
+    }
+
+  def e3 =
+    "input"                                   || "result"                      |
+    "全地域"                                  !! List(AllArea)                 |
+    "北海道/青森県/岩手県"                    !! List(Hokkaido, Aomori, Iwate) |
+    "関東エリアのすべて/甲信越エリアのすべて" !! List(AllKanto, AllKoshinetsu) |> { (input, result) =>
+      AsurakuStatus.parseAreasVld(input) must equalTo(result.success)
+    }
+
+  def e4 =
+    "input"                 || "result"  |
+    ""                      !! "failure" |
+    "/"                     !! "failure" |
+    "abc"                   !! "failure" |
+    "北海道/ダミー/岩手県"  !! "failure" |
+    "北海道/"               !! "failure" |
+    "/甲信越エリアのすべて" !! "failure" |> { (input, result) =>
+      AsurakuStatus.parseAreasVld(input).toEither must beLeft.like {
+        case JsonParseError(_) => ok
+      }
+    }
+
+  def e5 =
+    "closingTimeStr" || "areaStr" |
+    "10:00"          !! "東京都"  |
+    "dummy"          !! "東京都"  |
+    "10:00"          !! "dummy"   |
+    "dummy"          !! "dummy"   |> { (closingTimeStr, areaStr) =>
+      AsurakuStatus.parseVld(0, closingTimeStr, areaStr).toEither must beRight.like {
+        case DisableAsuraku => ok
+      }
+    }
+
+  def e6 =
+    "closingTimeStr" || "areaStr" | "result"                                                 |
+    "10:00"          !! "東京都"  ! AcceptAsuraku(new LocalTime(10, 0), List(Tokyo)).success |> {
+      (closingTimeStr, areaStr, result) =>
+        AsurakuStatus.parseVld(1, closingTimeStr, areaStr) must equalTo(result)
+    }
+
+  def e7 =
+    "closingTimeStr" || "areaStr" |
+    "dummy"          !! "東京都"  |
+    "10:00"          !! "dummy"   |
+    "dummy"          !! "dummy"   |> { (closingTimeStr, areaStr) =>
+        AsurakuStatus.parseVld(1, closingTimeStr, areaStr).toEither must beLeft.like {
+          case JsonParseError(_) => ok
+        }
+    }
+
+  def e8 =
+    "flag" | "closingTimeStr" | "areaStr" |
+    -1     ! "10:00"          ! "東京都"  |
+    2      ! "dummy"          ! "東京都"  |
+    100    ! "10:00"          ! "dummy"   |
+    999    ! "dummy"          ! "dummy"   |> { (flag, closingTimeStr, areaStr) =>
+        AsurakuStatus.parseVld(flag, closingTimeStr, areaStr).toEither must beLeft.like {
+          case JsonParseError(_) => ok
+        }
+    }
+}
[from now] 2012年 9月 23日 日曜日 22:54:15 JST

diff --git a/core/src/main/scala/webservice/response/ichiba/IchibaItemSearchResult.scala b/core/src/main/scala/webservice/response/ichiba/IchibaItemSearchResult.scala
index e48e1cc..ee9708e 100644
--- a/core/src/main/scala/webservice/response/ichiba/IchibaItemSearchResult.scala
+++ b/core/src/main/scala/webservice/response/ichiba/IchibaItemSearchResult.scala
@@ -78,7 +78,7 @@ object Item {

   val strOpt: String => Option[String] = {
     case "" => none
-    case s => s.some
+    case s => Option(s)
   }

   def doubleVld(str: String, paramName: String): Validation[ApiError, Double] =
diff --git a/core/src/test/scala/webservice/response/ichiba/ItemSpec.scala b/core/src/test/scala/webservice/response/ichiba/ItemSpec.scala
new file mode 100644
index 0000000..77ddae7
--- /dev/null
+++ b/core/src/test/scala/webservice/response/ichiba/ItemSpec.scala
@@ -0,0 +1,52 @@
+package jp.co.rakuten.webservice
+
+import org.specs2._, matcher.DataTables
+import scalaz._, Scalaz._
+
+class ItemSpec extends Specification with DataTables { def is =
+
+  "Item"                                                                                            ^
+    "strOpt"                                                                                        ^
+      "空文字かnullの場合はNone、それ以外の場合はその入力文字列のSomeを返す"                        ! e1^
+                                                                                                    p^
+    "doubleVld"                                                                                     ^
+      "Doubleにparseできる場合はDouble値のsuccessを返す"                                            ! e2^
+      "Doubleにparseできない場合はparamNameをmsgに含むJsonParseErrorのfailureを返す"                ! e3^
+                                                                                                    p^
+    "TODO"                                                                                          ^
+      "Itemのテスト作ってから、実装をIchibaItemSearchResult.scalaから別ファイルに切り出す"          ! ee^
+                                                                                                    end
+
+  def e1 =
+    "input "       || "result"       |
+    ""             !! None           |
+    (null: String) !! None           |
+    "string"       !! Some("string") |> { (input, result) =>
+      Item.strOpt(input) must equalTo(result)
+    }
+
+  def e2 =
+    "input" || "result"      |
+    "0.0"   !! 0.0.success   |
+    "1.2"   !! 1.2.success   |
+    "-2.4"  !! -2.4.success   |
+    "+4.7"  !! 4.7.success   |
+    "123"   !! 123.0.success |> { (input, result) =>
+      Item.doubleVld(input, "test") must equalTo(result)
+    }
+
+  def e3 =
+    "input"  || "result"  |
+    ""       !! "failure" |
+    "abc"    !! "failure" |
+    "日本語" !! "failure" |
+    "a12.3"  !! "failure" |
+    "12.3a"  !! "failure" |> { (input, _) =>
+      Item.doubleVld(input, "test").toEither must beLeft.like {
+        case JsonParseError(msg) => msg must contain("test")
+      }
+    }
+
+  def ee = ko
+}
+