Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed problem with test failure in windows. #640

Merged
merged 2 commits into from
Mar 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions release-notes/CREDITS-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ WrongWrong (@k163377)
* #629: Changed to not cache valueParameters
* #631: Fix minor bugs in SimpleModule.addSerializer/addDeserializer
* #634: Fix ReflectionCache to be serializable
* #640: Fixed problem with test failure in windows.

# 2.14.0

Expand Down
13 changes: 13 additions & 0 deletions src/test/kotlin/com/fasterxml/jackson/module/kotlin/TestCommons.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.fasterxml.jackson.module.kotlin

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

// 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: DefaultPrettyPrinter =
DefaultPrettyPrinter().withObjectIndenter(DefaultIndenter().withLinefeed("\n"))

fun ObjectMapper.testPrettyWriter(): ObjectWriter = this.writer(LF_PRINTER)
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.fasterxml.jackson.databind.module.SimpleModule
import com.fasterxml.jackson.databind.ser.std.StdSerializer
import com.fasterxml.jackson.module.kotlin.jacksonMapperBuilder
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.fasterxml.jackson.module.kotlin.testPrettyWriter
import org.junit.Test
import kotlin.test.assertEquals
import kotlin.test.assertNotEquals
Expand Down Expand Up @@ -39,7 +40,7 @@ class GitHub524 {
fun test() {
val sm = SimpleModule()
.addSerializer(Serializer())
val writer = jacksonMapperBuilder().addModule(sm).build().writerWithDefaultPrettyPrinter()
val writer = jacksonMapperBuilder().addModule(sm).build().testPrettyWriter()

// 18446744073709551615 is ULong.MAX_VALUE.
assertEquals(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.fasterxml.jackson.module.kotlin.test.github

import com.fasterxml.jackson.annotation.JsonValue
import com.fasterxml.jackson.module.kotlin.jacksonMapperBuilder
import com.fasterxml.jackson.module.kotlin.testPrettyWriter
import kotlin.test.assertEquals
import org.junit.Test

Expand Down Expand Up @@ -37,7 +38,7 @@ class GitHub530 {
@JvmInline
value class JsonValueGetterImplementation(val value: Int) : JsonValueGetter

private val writer = jacksonMapperBuilder().build().writerWithDefaultPrettyPrinter()
private val writer = jacksonMapperBuilder().build().testPrettyWriter()

@Test
fun valueParamGetterAnnotated() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.fasterxml.jackson.databind.ser.std.StdSerializer
import com.fasterxml.jackson.module.kotlin.KotlinModule
import com.fasterxml.jackson.module.kotlin.jacksonMapperBuilder
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.fasterxml.jackson.module.kotlin.testPrettyWriter
import org.junit.Ignore
import org.junit.Test
import kotlin.test.assertEquals
Expand Down Expand Up @@ -75,7 +76,7 @@ class Github464 {
@Suppress("UNCHECKED_CAST")
val writer: ObjectWriter = jacksonObjectMapper()
.apply { serializerProvider.setNullKeySerializer(NullValueClassKeySerializer as JsonSerializer<Any?>) }
.writerWithDefaultPrettyPrinter()
.testPrettyWriter()

assertEquals(
"""
Expand Down Expand Up @@ -117,7 +118,7 @@ class Github464 {
.apply {
serializerProvider.setNullKeySerializer(NullValueClassKeySerializer as JsonSerializer<Any?>)
serializerProvider.setNullValueSerializer(NullValueSerializer)
}.writerWithDefaultPrettyPrinter()
}.testPrettyWriter()

assertEquals(
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonInclude
import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.databind.MapperFeature.SORT_PROPERTIES_ALPHABETICALLY
import com.fasterxml.jackson.module.kotlin.jacksonMapperBuilder
import com.fasterxml.jackson.module.kotlin.testPrettyWriter
import org.junit.Ignore
import org.junit.Test
import kotlin.test.assertEquals
Expand All @@ -16,7 +17,7 @@ class TestGitHub337 {
.configure(SORT_PROPERTIES_ALPHABETICALLY, true)
.build()
.setSerializationInclusion(JsonInclude.Include.ALWAYS)
private val writer = mapper.writerWithDefaultPrettyPrinter()
private val writer = mapper.testPrettyWriter()

@Test
@Ignore
Expand Down