From 54dc8632ef1f96fe74593eeb808861bc552ffd60 Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Fri, 29 Dec 2023 14:51:49 +0100 Subject: [PATCH] upgrade circe to 0.14.6 and fix tests --- build.sbt | 2 +- .../pekkohttpavro4s/ExampleApp.scala | 2 +- .../pekkohttpcirce/CirceSupport.scala | 2 +- .../pekkohttpcirce/CirceSupportSpec.scala | 34 ++++++++++++------- 4 files changed, 25 insertions(+), 15 deletions(-) diff --git a/build.sbt b/build.sbt index 27179c7..e8e4664 100644 --- a/build.sbt +++ b/build.sbt @@ -225,7 +225,7 @@ lazy val library = val pekkoHttp = "1.0.0" val argonaut = "6.3.9" val avro4s = "4.1.1" - val circe = "0.14.1" + val circe = "0.14.6" val jacksonModuleScala = "2.16.1" val json4s = "4.0.7" val jsoniterScala = "2.26.2" diff --git a/pekko-http-avro4s/src/test/scala/com/github/pjfanning/pekkohttpavro4s/ExampleApp.scala b/pekko-http-avro4s/src/test/scala/com/github/pjfanning/pekkohttpavro4s/ExampleApp.scala index e3d8e6b..12d611c 100644 --- a/pekko-http-avro4s/src/test/scala/com/github/pjfanning/pekkohttpavro4s/ExampleApp.scala +++ b/pekko-http-avro4s/src/test/scala/com/github/pjfanning/pekkohttpavro4s/ExampleApp.scala @@ -60,7 +60,7 @@ object ExampleApp { } } ~ pathPrefix("stream") { post { - entity(as[SourceOf[Foo]]) { fooSource: SourceOf[Foo] => + entity(as[SourceOf[Foo]]) { (fooSource: SourceOf[Foo]) => import sys._ Marshal(Source.single(Foo("a"))).to[RequestEntity] diff --git a/pekko-http-circe/src/main/scala/com/github/pjfanning/pekkohttpcirce/CirceSupport.scala b/pekko-http-circe/src/main/scala/com/github/pjfanning/pekkohttpcirce/CirceSupport.scala index 945eab6..45e505e 100644 --- a/pekko-http-circe/src/main/scala/com/github/pjfanning/pekkohttpcirce/CirceSupport.scala +++ b/pekko-http-circe/src/main/scala/com/github/pjfanning/pekkohttpcirce/CirceSupport.scala @@ -68,7 +68,7 @@ trait FailFastCirceSupport extends BaseCirceSupport with FailFastUnmarshaller */ object ErrorAccumulatingCirceSupport extends ErrorAccumulatingCirceSupport { final case class DecodingFailures(failures: NonEmptyList[DecodingFailure]) extends Exception { - override def getMessage = failures.toList.map(_.show).mkString("\n") + override def getMessage: String = failures.toList.map(_.show).mkString("\n") } } diff --git a/pekko-http-circe/src/test/scala/com/github/pjfanning/pekkohttpcirce/CirceSupportSpec.scala b/pekko-http-circe/src/test/scala/com/github/pjfanning/pekkohttpcirce/CirceSupportSpec.scala index 2574283..f4eb0c8 100644 --- a/pekko-http-circe/src/test/scala/com/github/pjfanning/pekkohttpcirce/CirceSupportSpec.scala +++ b/pekko-http-circe/src/test/scala/com/github/pjfanning/pekkohttpcirce/CirceSupportSpec.scala @@ -23,6 +23,7 @@ import org.apache.pekko.http.scaladsl.model._ import org.apache.pekko.http.scaladsl.unmarshalling.Unmarshaller.UnsupportedContentTypeException import org.apache.pekko.http.scaladsl.unmarshalling.{ Unmarshal, Unmarshaller } import cats.data.{ NonEmptyList, ValidatedNel } +import cats.implicits.toShow import io.circe.CursorOp.DownField import io.circe.{ DecodingFailure, ParsingFailure, Printer } import org.scalatest.concurrent.ScalaFutures @@ -60,7 +61,7 @@ final class CirceSupportSpec /** * Specs common to both [[FailFastCirceSupport]] and [[ErrorAccumulatingCirceSupport]] */ - private def commonCirceSupport(support: BaseCirceSupport) = { + private def commonCirceSupport(support: BaseCirceSupport): Unit = { import io.circe.generic.auto._ import support._ @@ -131,21 +132,24 @@ final class CirceSupportSpec "fail-fast and return only the first unmarshalling error" in { val entity = HttpEntity(`application/json`, """{ "a": 1, "b": 2 }""") - val error = DecodingFailure("String", List(DownField("a"))) + val error = + DecodingFailure("Got value '1' with wrong type, expecting string", List(DownField("a"))) Unmarshal(entity) .to[MultiFoo] .failed - .map(_ shouldBe error) + .map(_.getMessage shouldBe error.getMessage()) } "fail-fast and return only the first unmarshalling error with safeUnmarshaller" in { val entity = HttpEntity(`application/json`, """{ "a": 1, "b": 2 }""") - val error = DecodingFailure("String", List(DownField("a"))) + val error: io.circe.Error = + DecodingFailure("Got value '1' with wrong type, expecting string", List(DownField("a"))) Unmarshal(entity) .to[Either[io.circe.Error, MultiFoo]] .futureValue .left - .value shouldBe error + .value + .getMessage shouldBe error.getMessage } "allow unmarshalling with passed in Content-Types" in { @@ -182,8 +186,8 @@ final class CirceSupportSpec val entity = HttpEntity(`application/json`, """{ "a": 1, "b": 2 }""") val errors = NonEmptyList.of( - DecodingFailure("String", List(DownField("a"))), - DecodingFailure("String", List(DownField("b"))) + DecodingFailure("Got value '1' with wrong type, expecting string", List(DownField("a"))), + DecodingFailure("Got value '2' with wrong type, expecting string", List(DownField("b"))) ) val errorMessage = ErrorAccumulatingCirceSupport.DecodingFailures(errors).getMessage Unmarshal(entity) @@ -194,18 +198,24 @@ final class CirceSupportSpec "accumulate and return all unmarshalling errors with safeUnmarshaller" in { val entity = HttpEntity(`application/json`, """{ "a": 1, "b": 2 }""") - val errors = + val errors: NonEmptyList[DecodingFailure] = NonEmptyList.of( - DecodingFailure("String", List(DownField("a"))), - DecodingFailure("String", List(DownField("b"))) + DecodingFailure("Got value '1' with wrong type, expecting string", List(DownField("a"))), + DecodingFailure("Got value '2' with wrong type, expecting string", List(DownField("b"))) ) val errorMessage = ErrorAccumulatingCirceSupport.DecodingFailures(errors).getMessage - Unmarshal(entity) + val result: String = Unmarshal(entity) .to[ValidatedNel[io.circe.Error, MultiFoo]] .futureValue .toEither .left - .value shouldBe errors + .value + .collect { case df: DecodingFailure => + df.show + } + .mkString("\n") + + errorMessage shouldBe result } "allow unmarshalling with passed in Content-Types" in {