Skip to content

Commit 2ca611c

Browse files
author
Martin Raison
committed
tests
1 parent 49215e1 commit 2ca611c

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

build.sbt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ scalaVersion := "2.11.1"
88

99
crossScalaVersions := Seq("2.10.2", "2.10.3", "2.10.4", "2.11.0", "2.11.1")
1010

11-
resolvers += Resolver.sonatypeRepo("releases")
11+
resolvers ++= Seq(
12+
Resolver.sonatypeRepo("releases"),
13+
"Typesafe Repo" at "http://repo.typesafe.com/typesafe/releases/"
14+
)
1215

1316
libraryDependencies <+= (scalaVersion)("org.scala-lang" % "scala-reflect" % _)
1417

@@ -17,6 +20,11 @@ libraryDependencies ++= (
1720
else Nil
1821
)
1922

23+
libraryDependencies ++= Seq(
24+
"com.typesafe.play" %% "play-json" % "2.3.1" % Test,
25+
"org.specs2" %% "specs2" % "2.3.13" % Test
26+
)
27+
2028
unmanagedSourceDirectories in Compile <+= (sourceDirectory in Compile, scalaBinaryVersion){
2129
(sourceDir, version) => sourceDir / (if (version.startsWith("2.10")) "scala_2.10" else "scala_2.11")
2230
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.kifi.macros
2+
3+
import org.specs2.mutable.Specification
4+
import play.api.libs.json._
5+
6+
@json case class City(name: String)
7+
8+
@json case class Person(name: String, age: Int)
9+
10+
class JsonFormatAnnotationTest extends Specification {
11+
12+
"@json annotation" should {
13+
14+
"create correct formatter for case class with 1 field" in {
15+
16+
val city = City("San Francisco")
17+
val json = Json.toJson(city)
18+
json === JsString("San Francisco")
19+
Json.fromJson[City](json) === JsSuccess(city)
20+
}
21+
22+
"create correct formatter for case class with >= 2 fields" in {
23+
24+
val person = Person("Victor Hugo", 46)
25+
val json = Json.toJson(person)
26+
json === Json.obj(
27+
"name" -> "Victor Hugo",
28+
"age" -> 46
29+
)
30+
Json.fromJson[Person](json) === JsSuccess(person)
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)