Skip to content

Commit

Permalink
Update MergeTest.scala
Browse files Browse the repository at this point in the history
(cherry picked from commit 98bc8e1)
  • Loading branch information
pjfanning committed Dec 20, 2020
1 parent 9a56d6e commit dc51439
Showing 1 changed file with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@ class MergeTest extends DeserializerTest {
behavior of "The DefaultScalaModule when reading for updating"

it should "merge both lists" in {
val typeReference = new TypeReference[ClassWithLists] {}
val initial = deserialize(classJson(firstListJson), typeReference)
val result = updateValue(newMergeableScalaMapper, initial, typeReference, classJson(secondListJson))
val clazz = classOf[ClassWithLists]
val initial = deserialize(classJson(firstListJson), clazz)
val result = updateValue(newMergeableScalaMapper, initial, clazz, classJson(secondListJson))

result shouldBe ClassWithLists(mergedList, mergedList)
}

it should "merge only the annotated list" in {
val typeReference = new TypeReference[ClassWithLists] {}
val initial = deserialize(classJson(firstListJson), typeReference)
val result = updateValue(newScalaMapper, initial, typeReference, classJson(secondListJson))
val clazz = classOf[ClassWithLists]
val initial = deserialize(classJson(firstListJson), clazz)
val result = updateValue(newScalaMapper, initial, clazz, classJson(secondListJson))

result shouldBe ClassWithLists(secondList, mergedList)
}
Expand Down Expand Up @@ -120,8 +120,18 @@ class MergeTest extends DeserializerTest {
objectReaderFor(mapper, valueToUpdate, typeReference).readValue(src)
}

private def updateValue[T](mapper: ObjectMapper, valueToUpdate: T,
clazz: Class[T], src: String): T = {
objectReaderFor(mapper, valueToUpdate, clazz).readValue(src)
}

private def objectReaderFor[T](mapper: ObjectMapper, valueToUpdate: T,
typeReference: TypeReference[T]): ObjectReader = {
mapper.readerForUpdating(valueToUpdate).forType(typeReference)
}

private def objectReaderFor[T](mapper: ObjectMapper, valueToUpdate: T,
clazz: Class[T]): ObjectReader = {
mapper.readerForUpdating(valueToUpdate).forType(clazz)
}
}

0 comments on commit dc51439

Please sign in to comment.