Skip to content

Commit 835c1bc

Browse files
committed
Add test cases
1 parent bab4ecb commit 835c1bc

5 files changed

+3891
-0
lines changed

src/test/kotlin/com/fasterxml/jackson/module/kotlin/TestCommons.kt

+18
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,28 @@ import com.fasterxml.jackson.core.util.DefaultIndenter
55
import com.fasterxml.jackson.core.util.DefaultPrettyPrinter
66
import com.fasterxml.jackson.databind.ObjectMapper
77
import com.fasterxml.jackson.databind.ObjectWriter
8+
import kotlin.reflect.KParameter
9+
import kotlin.reflect.full.memberProperties
10+
import kotlin.reflect.full.primaryConstructor
11+
import kotlin.test.assertEquals
812

913
// This `printer` is used to match the output from Jackson to the newline char of the source code.
1014
// If this is removed, comparisons will fail in a Windows-like platform.
1115
val LF_PRINTER: PrettyPrinter =
1216
DefaultPrettyPrinter().withObjectIndenter(DefaultIndenter().withLinefeed("\n"))
1317

1418
fun ObjectMapper.testPrettyWriter(): ObjectWriter = this.writer().with(LF_PRINTER)
19+
internal val defaultMapper = jacksonObjectMapper()
20+
21+
internal inline fun <reified T : Any> callPrimaryConstructor(mapper: (KParameter) -> Any? = { it.name }): T =
22+
T::class.primaryConstructor!!.run {
23+
val args = parameters.associateWith { mapper(it) }
24+
callBy(args)
25+
}
26+
27+
// Function for comparing non-data classes.
28+
internal inline fun <reified T : Any> assertReflectEquals(expected: T, actual: T) {
29+
T::class.memberProperties.forEach {
30+
assertEquals(it.get(expected), it.get(actual))
31+
}
32+
}

0 commit comments

Comments
 (0)