aboutsummaryrefslogtreecommitdiff
path: root/src/test/scala/FormatTests.scala
blob: f9cae2dfa8cf40686ed28ccc1112936eae1f738a (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 checkRoundtrip[A: RootJsonFormat](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)
    }
  }

}