Permalink
Browse files

Add tests for @ConfiguredJsonCodec with object modifiers

  • Loading branch information...
travisbrown committed Oct 30, 2018
1 parent 753ac3e commit f38f73cfecbe25b514fb45ef434d3c26693000b9
@@ -6,7 +6,6 @@ import io.circe.literal._
import io.circe.testing.CodecTests
import io.circe.tests.CirceSuite
import org.scalacheck.{ Arbitrary, Gen }
import org.scalacheck.Arbitrary.arbitrary
object ConfiguredJsonCodecSuite {
implicit val customConfig: Configuration =
@@ -23,9 +22,9 @@ object ConfiguredJsonCodecSuite {
object ConfigExampleFoo {
implicit val eqConfigExampleFoo: Eq[ConfigExampleFoo] = Eq.fromUniversalEquals
val genConfigExampleFoo: Gen[ConfigExampleFoo] = for {
thisIsAField <- arbitrary[String]
a <- arbitrary[Int]
b <- arbitrary[Double]
thisIsAField <- Arbitrary.arbitrary[String]
a <- Arbitrary.arbitrary[Int]
b <- Arbitrary.arbitrary[Double]
} yield ConfigExampleFoo(thisIsAField, a, b)
implicit val arbitraryConfigExampleFoo: Arbitrary[ConfigExampleFoo] = Arbitrary(genConfigExampleFoo)
}
@@ -36,13 +35,26 @@ object ConfiguredJsonCodecSuite {
ConfigExampleFoo.genConfigExampleFoo
implicit val arbitraryConfigExampleBase: Arbitrary[ConfigExampleBase] = Arbitrary(genConfigExampleBase)
}
@ConfiguredJsonCodec private[circe] final case class AccessModifier(a: Int)
private[circe] object AccessModifier {
implicit def eqAccessModifier: Eq[AccessModifier] = Eq.fromUniversalEquals
implicit def arbitraryAccessModifier: Arbitrary[AccessModifier] =
Arbitrary(
for {
a <- Arbitrary.arbitrary[Int]
} yield AccessModifier(a)
)
}
}
}
class ConfiguredJsonCodecSuite extends CirceSuite {
import ConfiguredJsonCodecSuite._, localExamples._
checkLaws("Codec[ConfigExampleBase]", CodecTests[ConfigExampleBase].codec)
checkLaws("Codec[AccessModifier]", CodecTests[AccessModifier].codec)
"ConfiguredJsonCodec" should "support configuration" in forAll { (f: String, b: Double) =>
val foo: ConfigExampleBase = ConfigExampleFoo(f, 0, b)

0 comments on commit f38f73c

Please sign in to comment.