diff --git a/chimney/src/test/scala/io/scalaland/chimney/PartialTransformerImplicitResolutionSpec.scala b/chimney/src/test/scala/io/scalaland/chimney/PartialTransformerImplicitResolutionSpec.scala index b53394fa7..119df3d6d 100644 --- a/chimney/src/test/scala/io/scalaland/chimney/PartialTransformerImplicitResolutionSpec.scala +++ b/chimney/src/test/scala/io/scalaland/chimney/PartialTransformerImplicitResolutionSpec.scala @@ -3,6 +3,8 @@ package io.scalaland.chimney import io.scalaland.chimney.dsl.* import io.scalaland.chimney.fixtures.* +import scala.annotation.unused + class PartialTransformerImplicitResolutionSpec extends ChimneySpec { test("transform using implicit Total Transformer for whole transformation when available") { @@ -68,4 +70,17 @@ class PartialTransformerImplicitResolutionSpec extends ChimneySpec { result2.asEither ==> Right(expected) result2.asErrorPathMessageStrings ==> Iterable.empty } + + test("ignore implicit Partial Transformer if an override is present") { + import trip.* + + @unused implicit def instance: PartialTransformer[Person, User] = PartialTransformer.derive + + val expected = User("Not John", 10, 140) + + val result = Person("John", 10, 140).intoPartial[User].withFieldConst(_.name, "Not John").transform + result.asOption ==> Some(expected) + result.asEither ==> Right(expected) + result.asErrorPathMessageStrings ==> Iterable.empty + } } diff --git a/chimney/src/test/scala/io/scalaland/chimney/TotalTransformerImplicitResolutionSpec.scala b/chimney/src/test/scala/io/scalaland/chimney/TotalTransformerImplicitResolutionSpec.scala index 2c42d7a68..4725dbb68 100644 --- a/chimney/src/test/scala/io/scalaland/chimney/TotalTransformerImplicitResolutionSpec.scala +++ b/chimney/src/test/scala/io/scalaland/chimney/TotalTransformerImplicitResolutionSpec.scala @@ -3,6 +3,8 @@ package io.scalaland.chimney import io.scalaland.chimney.dsl.* import io.scalaland.chimney.fixtures.* +import scala.annotation.unused + class TotalTransformerImplicitResolutionSpec extends ChimneySpec { test("transform using implicit Total Transformer for whole transformation when available") { @@ -29,4 +31,12 @@ class TotalTransformerImplicitResolutionSpec extends ChimneySpec { Person("John", 10, 140).into[User].transform ==> User("John", 10, 140) Person("John", 10, 140).transformInto[User] ==> User("John", 10, 140) } + + test("ignore implicit Total Transformer if an override is present") { + import trip.* + + @unused implicit def instance: Transformer[Person, User] = Transformer.derive + + Person("John", 10, 140).into[User].withFieldConst(_.name, "Not John").transform ==> User("Not John", 10, 140) + } }