Created
July 29, 2012 00:07
-
-
Save binarytemple/3195371 to your computer and use it in GitHub Desktop.
Specs test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"twitter json to Scala class mapper" should { | |
"parsing a tweet" in { | |
TwitterJsonMapper.tweetP(tweetS) match { | |
case Right(t: Tweet) => { | |
implicit def unOption[T](t: Option[T]): T = t.get | |
implicit def unEither[T](t: Either[T,Throwable]): T = t match {case Left(left) => left ;case Right(t) => throw t} | |
"test id" in { | |
true must_== (t.id.get == 228106060337135617l) | |
} | |
"test id_str" in { | |
true must_== (t.id_str.get == "228106060337135617") | |
} | |
"test time" in { | |
true must_== (t.created_at.getHours == 13 ) | |
} | |
} | |
case Left((pe: JsonParseException, reason: String)) => fail(reason + "\n" + pe) | |
} | |
} | |
} | |
case class Tweet( | |
@BeanProperty contributors: Option[String], | |
@BeanProperty coordinates: Option[String], | |
@BeanProperty @JsonDeserialize ( | |
using = classOf[TwitterDateDeserializer] | |
) created_at: Either[Date,Throwable], | |
@BeanProperty favorited: Boolean = false, | |
//elided etc etc | |
@BeanProperty id_str: Option[String] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment