Skip to content

Commit

Permalink
update arrow (#104)
Browse files Browse the repository at this point in the history
* update arrow

* update jackson to latest, use kotest property arrow

Co-authored-by: Mitchell Yuwono <myuwono@atlassian.com>
  • Loading branch information
i-walker and myuwono committed Sep 26, 2022
1 parent 9baeb3a commit 4d328d3
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 23 deletions.
3 changes: 2 additions & 1 deletion arrow-integrations-jackson-module/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ dependencies {
signature("net.sf.androidscents.signature:android-api-level-21:5.0.1_r2@signature")
implementation(libs.arrowCore)
implementation(libs.jacksonModuleKotlin)
testImplementation(libs.arrowCoreTest)
testImplementation(libs.kotest.property)
testImplementation(libs.kotest.propertyArrow)
testImplementation(libs.kotest.assertionsArrow)
testImplementation(libs.kotest.runnerJUnit5)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import arrow.core.Either
import arrow.core.Option
import arrow.core.left
import arrow.core.right
import arrow.core.test.generators.either
import arrow.core.test.generators.option
import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.readValue
Expand All @@ -25,6 +23,8 @@ import io.kotest.property.arbitrary.list
import io.kotest.property.arbitrary.orNull
import io.kotest.property.arbitrary.pair
import io.kotest.property.arbitrary.string
import io.kotest.property.arrow.core.either
import io.kotest.property.arrow.core.option
import io.kotest.property.checkAll

class EitherModuleTest : FunSpec() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import arrow.core.Option
import arrow.core.bothIor
import arrow.core.leftIor
import arrow.core.rightIor
import arrow.core.test.generators.ior
import arrow.core.test.generators.option
import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.registerKotlinModule
Expand All @@ -19,12 +17,14 @@ import io.kotest.property.arbitrary.alphanumeric
import io.kotest.property.arbitrary.arbitrary
import io.kotest.property.arbitrary.az
import io.kotest.property.arbitrary.boolean
import io.kotest.property.arbitrary.choice
import io.kotest.property.arbitrary.enum
import io.kotest.property.arbitrary.filter
import io.kotest.property.arbitrary.int
import io.kotest.property.arbitrary.orNull
import io.kotest.property.arbitrary.pair
import io.kotest.property.arbitrary.string
import io.kotest.property.arrow.core.option
import io.kotest.property.checkAll

class IorModuleTest : FunSpec() {
Expand Down Expand Up @@ -175,5 +175,12 @@ class IorModuleTest : FunSpec() {

private val arbTestClass: Arb<TestClass> = arbitrary { TestClass(Arb.ior(arbFoo, arbBar).bind()) }

private fun <L, R> Arb.Companion.ior(arbL: Arb<L>, arbR: Arb<R>): Arb<Ior<L, R>> =
Arb.choice(
arbitrary { arbL.bind().leftIor() },
arbitrary { arbR.bind().rightIor() },
arbitrary { (arbL.bind() to arbR.bind()).bothIor() }
)

private val mapper = ObjectMapper().registerKotlinModule().registerArrowModule()
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,26 @@ package arrow.integrations.jackson.module

import arrow.core.Nel
import arrow.core.NonEmptyList
import arrow.core.test.UnitSpec
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.jacksonTypeRef
import com.fasterxml.jackson.module.kotlin.registerKotlinModule
import io.kotest.assertions.throwables.shouldNotThrowAny
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe
import io.kotest.property.Arb
import io.kotest.property.arbitrary.arbitrary
import io.kotest.property.arbitrary.boolean
import io.kotest.property.arbitrary.choice
import io.kotest.property.arbitrary.int
import io.kotest.property.arbitrary.string
import io.kotest.property.arrow.core.nonEmptyList
import io.kotest.property.checkAll

class NonEmptyListModuleTest : UnitSpec() {
class NonEmptyListModuleTest : FunSpec() {
private val mapper = ObjectMapper().registerModule(NonEmptyListModule).registerKotlinModule()

init {
"serializing NonEmptyList should be the same as serializing the underlying list" {
test("serializing NonEmptyList should be the same as serializing the underlying list") {
checkAll(
Arb.nonEmptyList(Arb.choice(Arb.someObject(), Arb.int(), Arb.string(), Arb.boolean()))
) { list ->
Expand All @@ -30,7 +32,9 @@ class NonEmptyListModuleTest : UnitSpec() {
}
}

"serializing NonEmptyList and then deserialize it should be the same as before the deserialization" {
test(
"serializing NonEmptyList and then deserialize it should be the same as before the deserialization"
) {
checkAll(
Arb.choice(
arbitrary {
Expand All @@ -48,7 +52,7 @@ class NonEmptyListModuleTest : UnitSpec() {
}
}

"serializing NonEmptyList in an object should round trip" {
test("serializing NonEmptyList in an object should round trip") {
data class Wrapper(val nel: Nel<SomeObject>)
checkAll(arbitrary { Wrapper(Arb.nonEmptyList(Arb.someObject()).bind()) }) { wrapper ->
val encoded: String = mapper.writeValueAsString(wrapper)
Expand All @@ -58,7 +62,7 @@ class NonEmptyListModuleTest : UnitSpec() {
}
}

"should round trip on NonEmptyList with wildcard type" {
test("should round trip on NonEmptyList with wildcard type") {
val mapperWithSettings = ObjectMapper().registerKotlinModule().registerArrowModule()

checkAll(Arb.nonEmptyList(Arb.string())) { original: NonEmptyList<*> ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,27 @@ package arrow.integrations.jackson.module

import arrow.core.Option
import arrow.core.some
import arrow.core.test.UnitSpec
import arrow.core.test.generators.option
import com.fasterxml.jackson.annotation.JsonInclude
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.jacksonTypeRef
import com.fasterxml.jackson.module.kotlin.registerKotlinModule
import io.kotest.assertions.throwables.shouldNotThrowAny
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe
import io.kotest.property.Arb
import io.kotest.property.arbitrary.arbitrary
import io.kotest.property.arbitrary.boolean
import io.kotest.property.arbitrary.choice
import io.kotest.property.arbitrary.int
import io.kotest.property.arbitrary.string
import io.kotest.property.arrow.core.option
import io.kotest.property.checkAll

class OptionModuleTest : UnitSpec() {
class OptionModuleTest : FunSpec() {
private val mapper = ObjectMapper().registerModule(OptionModule).registerKotlinModule()

init {
"serializing Option should be the same as serializing a nullable value" {
test("serializing Option should be the same as serializing a nullable value") {
checkAll(Arb.option(Arb.choice(Arb.someObject(), Arb.int(), Arb.string(), Arb.boolean()))) {
option ->
val actual = mapper.writeValueAsString(option)
Expand All @@ -31,7 +32,9 @@ class OptionModuleTest : UnitSpec() {
}
}

"serializing Option with Include.NON_ABSENT should honor such configuration and omit serialization when option is empty" {
test(
"serializing Option with Include.NON_ABSENT should honor such configuration and omit serialization when option is empty"
) {
val mapperWithSettings =
ObjectMapper()
.registerModule(OptionModule)
Expand All @@ -50,7 +53,9 @@ class OptionModuleTest : UnitSpec() {
}
}

"serializing Option and then deserialize it should be the same as before the deserialization" {
test(
"serializing Option and then deserialize it should be the same as before the deserialization"
) {
checkAll(
Arb.choice(
arbitrary { Arb.option(Arb.someObject()).bind() to jacksonTypeRef<Option<SomeObject>>() },
Expand All @@ -66,7 +71,7 @@ class OptionModuleTest : UnitSpec() {
}
}

"should round-trip on wildcard types" {
test("should round-trip on wildcard types") {
val mapper = ObjectMapper().registerArrowModule()
checkAll(Arb.option(Arb.int(1..10))) { original: Option<*> ->
val serialized = mapper.writeValueAsString(original)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package arrow.integrations.jackson.module
import arrow.core.Option
import arrow.core.Validated
import arrow.core.invalid
import arrow.core.test.generators.option
import arrow.core.test.generators.validated
import arrow.core.valid
import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.databind.ObjectMapper
Expand All @@ -23,6 +21,8 @@ import io.kotest.property.arbitrary.int
import io.kotest.property.arbitrary.orNull
import io.kotest.property.arbitrary.pair
import io.kotest.property.arbitrary.string
import io.kotest.property.arrow.core.option
import io.kotest.property.arrow.core.validated
import io.kotest.property.checkAll

class ValidatedModuleTest : FunSpec() {
Expand Down
8 changes: 5 additions & 3 deletions gradle/projects.libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
[versions]
arrow = "1.1.2"
arrow = "1.1.3"
dokka = "1.7.0"
arrowGradleConfig = "0.10.1"
kotlin = "1.6.21"
kotest = "5.3.1"
kotlinBinaryCompatibilityValidator = "0.10.1"
detekt = "1.20.0"
animalsniffer = "1.5.4"
jacksonModuleKotlin = "2.13.3"
jacksonModuleKotlin = "2.13.4"
animalsnifferAnnoation = "1.21"
kotestExtensionsArrow = "1.2.5"

[libraries]
arrowAnnotations = { module = "io.arrow-kt:arrow-annotations", version.ref = "arrow" }
arrowCore = { module = "io.arrow-kt:arrow-core", version.ref = "arrow" }
arrowCoreTest = { module = "io.arrow-kt:arrow-core-test", version.ref = "arrow" }
arrowOptics = { module = "io.arrow-kt:arrow-optics", version.ref = "arrow" }
jacksonModuleKotlin = { module = "com.fasterxml.jackson.module:jackson-module-kotlin", version.ref = "jacksonModuleKotlin" }
kotest-assertionsCore = { module = "io.kotest:kotest-assertions-core", version.ref = "kotest" }
kotest-frameworkEngine = { module = "io.kotest:kotest-framework-engine", version.ref = "kotest" }
kotest-property = { module = "io.kotest:kotest-property", version.ref = "kotest" }
kotest-runnerJUnit5 = { module = "io.kotest:kotest-runner-junit5", version.ref = "kotest" }
kotest-propertyArrow = { module = "io.kotest.extensions:kotest-property-arrow", version.ref = "kotestExtensionsArrow" }
kotest-assertionsArrow = { module = "io.kotest.extensions:kotest-assertions-arrow", version.ref = "kotestExtensionsArrow" }
animalsniffer-annotation = {module = "org.codehaus.mojo:animal-sniffer-annotations", version.ref = "animalsnifferAnnoation"}

[plugins]
Expand Down

0 comments on commit 4d328d3

Please sign in to comment.