Skip to content

Commit 8e7aeb9

Browse files
authored
Merge pull request #640 from k163377/fix-test-on-windows
Fixed problem with test failure in windows.
2 parents 9c6e3bc + fba0842 commit 8e7aeb9

File tree

6 files changed

+23
-5
lines changed

6 files changed

+23
-5
lines changed

release-notes/CREDITS-2.x

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ WrongWrong (@k163377)
2626
* #629: Changed to not cache valueParameters
2727
* #631: Fix minor bugs in SimpleModule.addSerializer/addDeserializer
2828
* #634: Fix ReflectionCache to be serializable
29+
* #640: Fixed problem with test failure in windows.
2930

3031
# 2.14.0
3132

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.fasterxml.jackson.module.kotlin
2+
3+
import com.fasterxml.jackson.core.util.DefaultIndenter
4+
import com.fasterxml.jackson.core.util.DefaultPrettyPrinter
5+
import com.fasterxml.jackson.databind.ObjectMapper
6+
import com.fasterxml.jackson.databind.ObjectWriter
7+
8+
// This `printer` is used to match the output from Jackson to the newline char of the source code.
9+
// If this is removed, comparisons will fail in a Windows-like platform.
10+
val LF_PRINTER: DefaultPrettyPrinter =
11+
DefaultPrettyPrinter().withObjectIndenter(DefaultIndenter().withLinefeed("\n"))
12+
13+
fun ObjectMapper.testPrettyWriter(): ObjectWriter = this.writer(LF_PRINTER)

src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/GitHub524.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import com.fasterxml.jackson.databind.module.SimpleModule
77
import com.fasterxml.jackson.databind.ser.std.StdSerializer
88
import com.fasterxml.jackson.module.kotlin.jacksonMapperBuilder
99
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
10+
import com.fasterxml.jackson.module.kotlin.testPrettyWriter
1011
import org.junit.Test
1112
import kotlin.test.assertEquals
1213
import kotlin.test.assertNotEquals
@@ -39,7 +40,7 @@ class GitHub524 {
3940
fun test() {
4041
val sm = SimpleModule()
4142
.addSerializer(Serializer())
42-
val writer = jacksonMapperBuilder().addModule(sm).build().writerWithDefaultPrettyPrinter()
43+
val writer = jacksonMapperBuilder().addModule(sm).build().testPrettyWriter()
4344

4445
// 18446744073709551615 is ULong.MAX_VALUE.
4546
assertEquals(

src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/GitHub530.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.fasterxml.jackson.module.kotlin.test.github
22

33
import com.fasterxml.jackson.annotation.JsonValue
44
import com.fasterxml.jackson.module.kotlin.jacksonMapperBuilder
5+
import com.fasterxml.jackson.module.kotlin.testPrettyWriter
56
import kotlin.test.assertEquals
67
import org.junit.Test
78

@@ -37,7 +38,7 @@ class GitHub530 {
3738
@JvmInline
3839
value class JsonValueGetterImplementation(val value: Int) : JsonValueGetter
3940

40-
private val writer = jacksonMapperBuilder().build().writerWithDefaultPrettyPrinter()
41+
private val writer = jacksonMapperBuilder().build().testPrettyWriter()
4142

4243
@Test
4344
fun valueParamGetterAnnotated() {

src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github464.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import com.fasterxml.jackson.databind.ser.std.StdSerializer
1111
import com.fasterxml.jackson.module.kotlin.KotlinModule
1212
import com.fasterxml.jackson.module.kotlin.jacksonMapperBuilder
1313
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
14+
import com.fasterxml.jackson.module.kotlin.testPrettyWriter
1415
import org.junit.Ignore
1516
import org.junit.Test
1617
import kotlin.test.assertEquals
@@ -75,7 +76,7 @@ class Github464 {
7576
@Suppress("UNCHECKED_CAST")
7677
val writer: ObjectWriter = jacksonObjectMapper()
7778
.apply { serializerProvider.setNullKeySerializer(NullValueClassKeySerializer as JsonSerializer<Any?>) }
78-
.writerWithDefaultPrettyPrinter()
79+
.testPrettyWriter()
7980

8081
assertEquals(
8182
"""
@@ -117,7 +118,7 @@ class Github464 {
117118
.apply {
118119
serializerProvider.setNullKeySerializer(NullValueClassKeySerializer as JsonSerializer<Any?>)
119120
serializerProvider.setNullValueSerializer(NullValueSerializer)
120-
}.writerWithDefaultPrettyPrinter()
121+
}.testPrettyWriter()
121122

122123
assertEquals(
123124
"""

src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/failing/GitHub337.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonInclude
44
import com.fasterxml.jackson.annotation.JsonProperty
55
import com.fasterxml.jackson.databind.MapperFeature.SORT_PROPERTIES_ALPHABETICALLY
66
import com.fasterxml.jackson.module.kotlin.jacksonMapperBuilder
7+
import com.fasterxml.jackson.module.kotlin.testPrettyWriter
78
import org.junit.Ignore
89
import org.junit.Test
910
import kotlin.test.assertEquals
@@ -16,7 +17,7 @@ class TestGitHub337 {
1617
.configure(SORT_PROPERTIES_ALPHABETICALLY, true)
1718
.build()
1819
.setSerializationInclusion(JsonInclude.Include.ALWAYS)
19-
private val writer = mapper.writerWithDefaultPrettyPrinter()
20+
private val writer = mapper.testPrettyWriter()
2021

2122
@Test
2223
@Ignore

0 commit comments

Comments
 (0)