Created
November 8, 2013 11:11
-
-
Save gbougeard/7369559 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| import models.Place | |
| import models.Place._ | |
| import org.specs2.mutable._ | |
| import org.specs2.ScalaCheck | |
| import play.api.libs.json.Json | |
| import org.scalacheck._ | |
| import Gen._ | |
| import Prop._ | |
| import Arbitrary._ | |
| /** | |
| * Add your spec here. | |
| * You can mock out a whole application including requests, plugins etc. | |
| * For more information, consult the wiki. | |
| */ | |
| object PlaceProp extends Properties("Place") { | |
| property("json from(to) iso") = forAll { | |
| p: Place => | |
| println(s"p: $p") | |
| println(s"tojson: ${Json.toJson(p)}") | |
| println(s"from(to): ${Json.fromJson(Json.toJson(p))}") | |
| Json.fromJson(Json.toJson(p)) == p | |
| } | |
| lazy val genPlace: Gen[Place] = for { | |
| id <- arbitrary[Long] | |
| if (id > 0) | |
| name <- arbitrary[String] | |
| if (!name.isEmpty) | |
| address <- arbitrary[String] | |
| if (!address.isEmpty) | |
| city <- arbitrary[String] | |
| if (!city.isEmpty) | |
| zipcode <- arbitrary[String] | |
| if (!zipcode.isEmpty) | |
| } yield Place(Some(id), name, address, city, zipcode) | |
| implicit lazy val arbHeap: Arbitrary[Place] = Arbitrary(genPlace) | |
| } | |
| class PlaceSpec extends Specification with ScalaCheck { | |
| "json from(to) iso" ! PlaceProp | |
| } |
This file contains hidden or 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
| [play-fam] $ testOnly PlaceSpec | |
| [info] Compiling 1 Scala source to /home/gbougeard/git/play-fam/target/scala-2.10/test-classes... | |
| [warn] /home/gbougeard/git/play-fam/test/PlaceSpec.scala:27: play.api.libs.json.JsResult[models.Place] and models.Place are unrelated: they will most likely never compare equal | |
| [warn] Json.fromJson(Json.toJson(p)) == p | |
| [warn] ^ | |
| [warn] one warning found | |
| p: Place(Some(2960914703493339579),䢂徔◻,ﶱ莋ꥑ纲딒,徧咃쫠螌,燱퇴낁,None,None,None,None) | |
| tojson: {"id":2960914703493339579,"name":"䢂徔◻","address":"ﶱ莋ꥑ纲딒","city":"徧咃쫠螌","zipcode":"燱퇴낁"} | |
| from(to): JsSuccess(Place(Some(2960914703493339579),䢂徔◻,ﶱ莋ꥑ纲딒,徧咃쫠螌,燱퇴낁,None,None,None,None),) | |
| [info] PlaceSpec | |
| [info] x json from(to) iso | |
| [error] A counter-example is 'Place(Some(2960914703493339579),䢂徔◻,ﶱ莋ꥑ纲딒,徧咃쫠螌,燱퇴낁,None,None,None,None)' (after 0 try) | |
| [info] Total for specification PlaceSpec | |
| [info] Finished in 345 ms | |
| [info] 1 example, 1 failure, 0 error | |
| [error] Failed: Total 1, Failed 1, Errors 0, Passed 0 | |
| [error] Failed tests: | |
| [error] PlaceSpec | |
| [error] (test:testOnly) sbt.TestsFailedException: Tests unsuccessful | |
| [error] Total time: 4 s, completed Nov 8, 2013 12:10:23 PM |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment