aboutsummaryrefslogtreecommitdiff
path: root/src/test/scala/FormatTests.scala
blob: e29e49f4e33a5ce1daf3806d7da16a1b0bf3fe3c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
package xyz.driver.json

import spray.json._
import org.scalatest._

trait FormatTests { self: FlatSpec =>

  def checkCoherence[A: JsonFormat](a: A, expectedJson: String) = {
    it should "serialize to the expected JSON value" in {
      val expected: JsValue = expectedJson.parseJson
      assert(a.toJson == expected)
    }

    it should "serialize then deserialize back to itself" in {
      val reread = a.toJson.convertTo[A]
      assert(reread == a)
    }
  }

}