Skip to content

Commit

Permalink
Better assertions in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zarthross committed May 13, 2023
1 parent a71fb90 commit 06fd37e
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class ConfiguredSemiautoDerivedScala2Suite extends CirceSuite {
_(field(j))
)

assert(result === Right(Qux(i, s, j)))
assertEquals(result, Right(Qux(i, s, j)))
}
}

Expand All @@ -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)))
}
}

Expand All @@ -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))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

Expand All @@ -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))
}
}

Expand All @@ -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))
}
}

Expand All @@ -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))
}
}

Expand All @@ -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") {
Expand All @@ -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"))))
Expand Down Expand Up @@ -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))
}
}

Expand All @@ -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))
}
}

Expand All @@ -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))
}
}

Expand All @@ -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))
}
}

Expand Down Expand Up @@ -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))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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))
}
}

Expand Down Expand Up @@ -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)
}
}

Expand All @@ -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))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand All @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand All @@ -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)
}
}

Expand Down

0 comments on commit 06fd37e

Please sign in to comment.