Skip to content

Commit

Permalink
Add test for ignoring the transformer when overrides are present
Browse files Browse the repository at this point in the history
  • Loading branch information
MateuszKubuszok committed Sep 15, 2023
1 parent 16d1f88 commit 78ac85e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down Expand Up @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand All @@ -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)
}
}

0 comments on commit 78ac85e

Please sign in to comment.