From 06fd37e0bce1a2c5018c546eaf5a12c6410cafc9 Mon Sep 17 00:00:00 2001 From: Darren Gibson Date: Fri, 14 Oct 2022 20:55:11 -0500 Subject: [PATCH] Better assertions in tests --- .../ConfiguredAutoDerivedScala2Suite.scala | 2 +- .../extras/ConfiguredJsonCodecSuite.scala | 4 +- .../ConfiguredJsonCodecWithKeySuite.scala | 4 +- ...ConfiguredSemiautoDerivedScala2Suite.scala | 6 +-- .../extras/ConfiguredAutoDerivedSuite.scala | 50 +++++++++---------- .../ConfiguredSemiautoDerivedSuite.scala | 18 +++---- .../EnumerationSemiautoDerivedSuite.scala | 4 +- .../UnwrappedSemiautoDerivedSuite.scala | 4 +- 8 files changed, 46 insertions(+), 46 deletions(-) diff --git a/generic-extras/src/test/scala-2/io/circe/generic/extras/ConfiguredAutoDerivedScala2Suite.scala b/generic-extras/src/test/scala-2/io/circe/generic/extras/ConfiguredAutoDerivedScala2Suite.scala index f4af1d3e..733693a4 100644 --- a/generic-extras/src/test/scala-2/io/circe/generic/extras/ConfiguredAutoDerivedScala2Suite.scala +++ b/generic-extras/src/test/scala-2/io/circe/generic/extras/ConfiguredAutoDerivedScala2Suite.scala @@ -26,7 +26,7 @@ class ConfiguredAutoDerivedScala2Suite extends CirceSuite { .as[Int => Qux[String]] .map(_(i)) - assert(result === Right(Qux(i, s, j))) + assertEquals(result, Right(Qux(i, s, j))) } } } diff --git a/generic-extras/src/test/scala-2/io/circe/generic/extras/ConfiguredJsonCodecSuite.scala b/generic-extras/src/test/scala-2/io/circe/generic/extras/ConfiguredJsonCodecSuite.scala index a8092741..7c5995ea 100644 --- a/generic-extras/src/test/scala-2/io/circe/generic/extras/ConfiguredJsonCodecSuite.scala +++ b/generic-extras/src/test/scala-2/io/circe/generic/extras/ConfiguredJsonCodecSuite.scala @@ -76,8 +76,8 @@ class ConfiguredJsonCodecSuite extends CirceSuite { val json = json"""{ "type": "config_example_foo", "this_is_a_field": $f, "b": $b}""" val expected = json"""{ "type": "config_example_foo", "this_is_a_field": $f, "a": 0, "b": $b}""" - assert(Encoder[ConfigExampleBase].apply(foo) === expected) - assert(Decoder[ConfigExampleBase].decodeJson(json) === Right(foo)) + assertEquals(Encoder[ConfigExampleBase].apply(foo), expected) + assertEquals(Decoder[ConfigExampleBase].decodeJson(json), Right(foo)) } } diff --git a/generic-extras/src/test/scala-2/io/circe/generic/extras/ConfiguredJsonCodecWithKeySuite.scala b/generic-extras/src/test/scala-2/io/circe/generic/extras/ConfiguredJsonCodecWithKeySuite.scala index abc1d811..3c79a2e5 100644 --- a/generic-extras/src/test/scala-2/io/circe/generic/extras/ConfiguredJsonCodecWithKeySuite.scala +++ b/generic-extras/src/test/scala-2/io/circe/generic/extras/ConfiguredJsonCodecWithKeySuite.scala @@ -45,8 +45,8 @@ class ConfiguredJsonCodecWithKeySuite extends CirceSuite { val json = json"""{ "type": "config_example_foo", "this_is_a_field": $f, "myField": $b}""" val expected = json"""{ "type": "config_example_foo", "this_is_a_field": $f, "a": 0, "myField": $b}""" - assert(Encoder[ConfigExampleBase].apply(foo) === expected) - assert(Decoder[ConfigExampleBase].decodeJson(json) === Right(foo)) + assertEquals(Encoder[ConfigExampleBase].apply(foo), expected) + assertEquals(Decoder[ConfigExampleBase].decodeJson(json), Right(foo)) } } } diff --git a/generic-extras/src/test/scala-2/io/circe/generic/extras/ConfiguredSemiautoDerivedScala2Suite.scala b/generic-extras/src/test/scala-2/io/circe/generic/extras/ConfiguredSemiautoDerivedScala2Suite.scala index 76622da0..96745e98 100644 --- a/generic-extras/src/test/scala-2/io/circe/generic/extras/ConfiguredSemiautoDerivedScala2Suite.scala +++ b/generic-extras/src/test/scala-2/io/circe/generic/extras/ConfiguredSemiautoDerivedScala2Suite.scala @@ -42,7 +42,7 @@ class ConfiguredSemiautoDerivedScala2Suite extends CirceSuite { _(field(j)) ) - assert(result === Right(Qux(i, s, j))) + assertEquals(result, Right(Qux(i, s, j))) } } @@ -56,7 +56,7 @@ class ConfiguredSemiautoDerivedScala2Suite extends CirceSuite { .as[Int => Qux[String]] .map(_(i)) - assert(result === Right(Qux(i, s, j))) + assertEquals(result, Right(Qux(i, s, j))) } } @@ -70,7 +70,7 @@ class ConfiguredSemiautoDerivedScala2Suite extends CirceSuite { val expected = Qux[String](i.getOrElse(q.i), a.getOrElse(q.a), j.getOrElse(q.j)) - assert(json.as[Qux[String] => Qux[String]].map(_(q)) === Right(expected)) + assertEquals(json.as[Qux[String] => Qux[String]].map(_(q)), Right(expected)) } } } diff --git a/generic-extras/src/test/scala/io/circe/generic/extras/ConfiguredAutoDerivedSuite.scala b/generic-extras/src/test/scala/io/circe/generic/extras/ConfiguredAutoDerivedSuite.scala index 865a0ca7..d58f6aa5 100644 --- a/generic-extras/src/test/scala/io/circe/generic/extras/ConfiguredAutoDerivedSuite.scala +++ b/generic-extras/src/test/scala/io/circe/generic/extras/ConfiguredAutoDerivedSuite.scala @@ -60,8 +60,8 @@ class ConfiguredAutoDerivedSuite extends CirceSuite { import foo._ val json = json"""{ "this_is_a_field": $thisIsAField, "a": $a, "b": $b}""" - assert(Encoder[ConfigExampleFoo].apply(foo) === json) - assert(Decoder[ConfigExampleFoo].decodeJson(json) === Right(foo)) + assertEquals(Encoder[ConfigExampleFoo].apply(foo), json) + assertEquals(Decoder[ConfigExampleFoo].decodeJson(json), Right(foo)) } } @@ -72,8 +72,8 @@ class ConfiguredAutoDerivedSuite extends CirceSuite { import foo._ val json = json"""{ "THIS_IS_A_FIELD": $thisIsAField, "A": $a, "B": $b}""" - assert(Encoder[ConfigExampleFoo].apply(foo) === json) - assert(Decoder[ConfigExampleFoo].decodeJson(json) === Right(foo)) + assertEquals(Encoder[ConfigExampleFoo].apply(foo), json) + assertEquals(Decoder[ConfigExampleFoo].decodeJson(json), Right(foo)) } } @@ -84,8 +84,8 @@ class ConfiguredAutoDerivedSuite extends CirceSuite { import foo._ val json = json"""{ "this-is-a-field": $thisIsAField, "a": $a, "b": $b}""" - assert(Encoder[ConfigExampleFoo].apply(foo) === json) - assert(Decoder[ConfigExampleFoo].decodeJson(json) === Right(foo)) + assertEquals(Encoder[ConfigExampleFoo].apply(foo), json) + assertEquals(Decoder[ConfigExampleFoo].decodeJson(json), Right(foo)) } } @@ -109,8 +109,8 @@ class ConfiguredAutoDerivedSuite extends CirceSuite { val json = json"""{ "thisIsAField": $f, "b": $b }""" val expected = json"""{ "thisIsAField": $f, "a": 0, "b": $b}""" - assert(Encoder[ConfigExampleFoo].apply(foo) === expected) - assert(Decoder[ConfigExampleFoo].decodeJson(json) === Right(foo)) + assertEquals(Encoder[ConfigExampleFoo].apply(foo), expected) + assertEquals(Decoder[ConfigExampleFoo].decodeJson(json), Right(foo)) } } @@ -129,12 +129,12 @@ class ConfiguredAutoDerivedSuite extends CirceSuite { test("Option[T] without default should be None if null decoded") { val json = json"""{ "a": null }""" - assert(Decoder[FooNoDefault].decodeJson(json) === Right(FooNoDefault(None, "b"))) + assertEquals(Decoder[FooNoDefault].decodeJson(json), Right(FooNoDefault(None, "b"))) } test("Option[T] without default should be None if missing key decoded") { val json = json"""{}""" - assert(Decoder[FooNoDefault].decodeJson(json) === Right(FooNoDefault(None, "b"))) + assertEquals(Decoder[FooNoDefault].decodeJson(json), Right(FooNoDefault(None, "b"))) } test("Option[T] with default should be None if null decoded") { @@ -144,19 +144,19 @@ class ConfiguredAutoDerivedSuite extends CirceSuite { test("Option[T] with default should be default value if missing key decoded") { val json = json"""{}""" - assert(Decoder[FooWithDefault].decodeJson(json) === Right(FooWithDefault(Some(0), "b"))) - assert(Decoder[FooWithDefault].decodeAccumulating(json.hcursor) === Validated.valid(FooWithDefault(Some(0), "b"))) + assertEquals(Decoder[FooWithDefault].decodeJson(json), Right(FooWithDefault(Some(0), "b"))) + assertEquals(Decoder[FooWithDefault].decodeAccumulating(json.hcursor), Validated.valid(FooWithDefault(Some(0), "b"))) } test("Value with default should be default value if value is null") { val json = json"""{"b": null}""" - assert(Decoder[FooWithDefault].decodeJson(json) === Right(FooWithDefault(Some(0), "b"))) - assert(Decoder[FooWithDefault].decodeAccumulating(json.hcursor) === Validated.valid(FooWithDefault(Some(0), "b"))) + assertEquals(Decoder[FooWithDefault].decodeJson(json), Right(FooWithDefault(Some(0), "b"))) + assertEquals(Decoder[FooWithDefault].decodeAccumulating(json.hcursor), Validated.valid(FooWithDefault(Some(0), "b"))) } test("Option[T] with default should fail to decode if type in json is not correct") { val json = json"""{"a": "NotAnInt"}""" - assert(Decoder[FooWithDefault].decodeJson(json) === Left(DecodingFailure("Int", List(DownField("a"))))) + assertEquals(Decoder[FooWithDefault].decodeJson(json), Left(DecodingFailure("Int", List(DownField("a"))))) assert( Decoder[FooWithDefault].decodeAccumulating(json.hcursor) === Validated.invalidNel(DecodingFailure("Int", List(DownField("a")))) @@ -187,8 +187,8 @@ class ConfiguredAutoDerivedSuite extends CirceSuite { import foo._ val json = json"""{ "type": "ConfigExampleFoo", "thisIsAField": $thisIsAField, "a": $a, "b": $b}""" - assert(Encoder[ConfigExampleBase].apply(foo) === json) - assert(Decoder[ConfigExampleBase].decodeJson(json) === Right(foo)) + assertEquals(Encoder[ConfigExampleBase].apply(foo), json) + assertEquals(Decoder[ConfigExampleBase].decodeJson(json), Right(foo)) } } @@ -200,8 +200,8 @@ class ConfiguredAutoDerivedSuite extends CirceSuite { import foo._ val json = json"""{ "type": "config_example_foo", "thisIsAField": $thisIsAField, "a": $a, "b": $b}""" - assert(Encoder[ConfigExampleBase].apply(foo) === json) - assert(Decoder[ConfigExampleBase].decodeJson(json) === Right(foo)) + assertEquals(Encoder[ConfigExampleBase].apply(foo), json) + assertEquals(Decoder[ConfigExampleBase].decodeJson(json), Right(foo)) } } @@ -215,8 +215,8 @@ class ConfiguredAutoDerivedSuite extends CirceSuite { import foo._ val json = json"""{ "type": "CONFIG_EXAMPLE_FOO", "thisIsAField": $thisIsAField, "a": $a, "b": $b}""" - assert(Encoder[ConfigExampleBase].apply(foo) === json) - assert(Decoder[ConfigExampleBase].decodeJson(json) === Right(foo)) + assertEquals(Encoder[ConfigExampleBase].apply(foo), json) + assertEquals(Decoder[ConfigExampleBase].decodeJson(json), Right(foo)) } } @@ -228,8 +228,8 @@ class ConfiguredAutoDerivedSuite extends CirceSuite { import foo._ val json = json"""{ "type": "config-example-foo", "thisIsAField": $thisIsAField, "a": $a, "b": $b}""" - assert(Encoder[ConfigExampleBase].apply(foo) === json) - assert(Decoder[ConfigExampleBase].decodeJson(json) === Right(foo)) + assertEquals(Encoder[ConfigExampleBase].apply(foo), json) + assertEquals(Decoder[ConfigExampleBase].decodeJson(json), Right(foo)) } } @@ -268,8 +268,8 @@ class ConfiguredAutoDerivedSuite extends CirceSuite { val json = json"""{ "type": "ConfigExampleFoo", "this_is_a_field": $f, "b": $b}""" val expected = json"""{ "type": "ConfigExampleFoo", "this_is_a_field": $f, "a": 0, "b": $b}""" - assert(Encoder[ConfigExampleBase].apply(foo) === expected) - assert(Decoder[ConfigExampleBase].decodeJson(json) === Right(foo)) + assertEquals(Encoder[ConfigExampleBase].apply(foo), expected) + assertEquals(Decoder[ConfigExampleBase].decodeJson(json), Right(foo)) } } diff --git a/generic-extras/src/test/scala/io/circe/generic/extras/ConfiguredSemiautoDerivedSuite.scala b/generic-extras/src/test/scala/io/circe/generic/extras/ConfiguredSemiautoDerivedSuite.scala index 316e5e75..7098fbb1 100644 --- a/generic-extras/src/test/scala/io/circe/generic/extras/ConfiguredSemiautoDerivedSuite.scala +++ b/generic-extras/src/test/scala/io/circe/generic/extras/ConfiguredSemiautoDerivedSuite.scala @@ -38,9 +38,9 @@ object ConfiguredSemiautoDerivedSuite { implicit val customConfig: Configuration = Configuration.default.withSnakeCaseMemberNames.withDefaults.withDiscriminator("type").withSnakeCaseConstructorNames - implicit val decodeConfigExampleBase: Decoder[ConfigExampleBase] = deriveConfiguredDecoder - implicit val encodeConfigExampleBase: Encoder.AsObject[ConfigExampleBase] = deriveConfiguredEncoder - val codecForConfigExampleBase: Codec.AsObject[ConfigExampleBase] = deriveConfiguredCodec + implicit lazy val decodeConfigExampleBase: Decoder[ConfigExampleBase] = deriveConfiguredDecoder + implicit lazy val encodeConfigExampleBase: Encoder.AsObject[ConfigExampleBase] = deriveConfiguredEncoder + lazy val codecForConfigExampleBase: Codec.AsObject[ConfigExampleBase] = deriveConfiguredCodec } class ConfiguredSemiautoDerivedSuite extends CirceSuite { @@ -66,8 +66,8 @@ class ConfiguredSemiautoDerivedSuite extends CirceSuite { val json = json"""{ "type": "config_example_foo", "this_is_a_field": $f, "b": $b}""" val expected = json"""{ "type": "config_example_foo", "this_is_a_field": $f, "a": 0, "b": $b}""" - assert(Encoder[ConfigExampleBase].apply(foo) === expected) - assert(Decoder[ConfigExampleBase].decodeJson(json) === Right(foo)) + assertEquals(Encoder[ConfigExampleBase].apply(foo), expected) + assertEquals(Decoder[ConfigExampleBase].decodeJson(json), Right(foo)) } } @@ -97,9 +97,9 @@ class ConfiguredSemiautoDerivedSuite extends CirceSuite { val foo: ConfigExampleBase = ConfigExampleFoo("field_value", 0, 100) val encoded = encoder.apply(foo) val decoded = decoder.decodeJson(encoded) - assert(decoded === Right(foo)) - assert(transformMemberNamesCallCount === fieldCount * 2) - assert(transformConstructorCallCount === decodeConstructorCount + encodeConstructorCount) + assertEquals(decoded, Right(foo)) + assertEquals(transformMemberNamesCallCount, fieldCount * 2) + assertEquals(transformConstructorCallCount, decodeConstructorCount + encodeConstructorCount) } } @@ -121,7 +121,7 @@ class ConfiguredSemiautoDerivedSuite extends CirceSuite { val expectedError = DecodingFailure("Unexpected field: [stowaway_field]; valid fields: this_is_a_field, a, b, type_field", Nil) - assert(Decoder[ConfigExampleBase].decodeJson(json) === Left(expectedError)) + assertEquals(Decoder[ConfigExampleBase].decodeJson(json), Left(expectedError)) } } diff --git a/generic-extras/src/test/scala/io/circe/generic/extras/EnumerationSemiautoDerivedSuite.scala b/generic-extras/src/test/scala/io/circe/generic/extras/EnumerationSemiautoDerivedSuite.scala index 6c749e60..8ed5280d 100644 --- a/generic-extras/src/test/scala/io/circe/generic/extras/EnumerationSemiautoDerivedSuite.scala +++ b/generic-extras/src/test/scala/io/circe/generic/extras/EnumerationSemiautoDerivedSuite.scala @@ -46,7 +46,7 @@ class EnumerationSemiautoDerivedSuite extends CirceSuite { implicit val config: Configuration = Configuration.default.withSnakeCaseConstructorNames val decodeMary = deriveEnumerationDecoder[Mary] val expected = json""""little_lamb"""" - assert(decodeMary.decodeJson(expected) === Right(LittleLamb)) + assertEquals(decodeMary.decodeJson(expected), Right(LittleLamb)) } test("deriveEnumerationEncoder should not compile on an ADT with case classes") { @@ -69,6 +69,6 @@ class EnumerationSemiautoDerivedSuite extends CirceSuite { implicit val config: Configuration = Configuration.default.withSnakeCaseConstructorNames val encodeMary = deriveEnumerationEncoder[Mary] val expected = json""""little_lamb"""" - assert(encodeMary(LittleLamb) === expected) + assertEquals(encodeMary(LittleLamb), expected) } } diff --git a/generic-extras/src/test/scala/io/circe/generic/extras/UnwrappedSemiautoDerivedSuite.scala b/generic-extras/src/test/scala/io/circe/generic/extras/UnwrappedSemiautoDerivedSuite.scala index 9898d312..e3321d7b 100644 --- a/generic-extras/src/test/scala/io/circe/generic/extras/UnwrappedSemiautoDerivedSuite.scala +++ b/generic-extras/src/test/scala/io/circe/generic/extras/UnwrappedSemiautoDerivedSuite.scala @@ -35,7 +35,7 @@ class UnwrappedSemiautoDerivedSuite extends CirceSuite { val foo = Foo(s) val expected = Json.fromString(s) - assert(Encoder[Foo].apply(foo) === expected) + assertEquals(Encoder[Foo].apply(foo), expected) } } @@ -44,7 +44,7 @@ class UnwrappedSemiautoDerivedSuite extends CirceSuite { val json = Json.fromString(s) val expected = Right(Foo(s)) - assert(Decoder[Foo].decodeJson(json) === expected) + assertEquals(Decoder[Foo].decodeJson(json), expected) } }