Skip to content

Commit

Permalink
Add test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
k163377 committed Jan 7, 2024
1 parent bab4ecb commit db80323
Show file tree
Hide file tree
Showing 5 changed files with 3,891 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/test/kotlin/com/fasterxml/jackson/module/kotlin/TestCommons.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,28 @@ import com.fasterxml.jackson.core.util.DefaultIndenter
import com.fasterxml.jackson.core.util.DefaultPrettyPrinter
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.databind.ObjectWriter
import kotlin.reflect.KParameter
import kotlin.reflect.full.memberProperties
import kotlin.reflect.full.primaryConstructor
import kotlin.test.assertEquals

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

fun ObjectMapper.testPrettyWriter(): ObjectWriter = this.writer().with(LF_PRINTER)
internal val defaultMapper = jacksonObjectMapper()

internal inline fun <reified T : Any> callPrimaryConstructor(mapper: (KParameter) -> Any? = { it.name }): T =
T::class.primaryConstructor!!.run {
val args = parameters.associateWith { mapper(it) }
callBy(args)
}

// Function for comparing non-data classes.
internal inline fun <reified T : Any> assertReflectEquals(expected: T, actual: T) {
T::class.memberProperties.forEach {
assertEquals(it.get(expected), it.get(actual))
}
}
Loading

0 comments on commit db80323

Please sign in to comment.