Skip to content

Commit 5db51ad

Browse files
authored
Merge pull request #984 from k163377/fix-tests
Fix and refactor tests
2 parents d1f80a7 + 7107d31 commit 5db51ad

File tree

5 files changed

+31
-22
lines changed

5 files changed

+31
-22
lines changed

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.core.exc.InputCoercionException
44
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
55
import com.fasterxml.jackson.module.kotlin.readValue
66
import org.junit.jupiter.api.Assertions.assertThrows
7+
import org.junit.jupiter.api.Nested
78
import org.junit.jupiter.api.Test
89
import java.math.BigInteger
910
import kotlin.test.assertEquals
@@ -13,7 +14,8 @@ internal class UnsignedNumbersOnKeyTest {
1314
val MAPPER = jacksonObjectMapper()
1415
}
1516

16-
class ForUByte {
17+
@Nested
18+
inner class ForUByte {
1719
private fun makeSrc(v: Int): String = MAPPER.writeValueAsString(mapOf(v to 0))
1820

1921
@Test
@@ -37,7 +39,8 @@ internal class UnsignedNumbersOnKeyTest {
3739
}
3840
}
3941

40-
class ForUShort {
42+
@Nested
43+
inner class ForUShort {
4144
private fun makeSrc(v: Int): String = MAPPER.writeValueAsString(mapOf(v to 0))
4245

4346
@Test
@@ -61,7 +64,8 @@ internal class UnsignedNumbersOnKeyTest {
6164
}
6265
}
6366

64-
class ForUInt {
67+
@Nested
68+
inner class ForUInt {
6569
private fun makeSrc(v: Long): String = MAPPER.writeValueAsString(mapOf(v to 0))
6670

6771
@Test
@@ -85,7 +89,8 @@ internal class UnsignedNumbersOnKeyTest {
8589
}
8690
}
8791

88-
class ForULong {
92+
@Nested
93+
inner class ForULong {
8994
private fun makeSrc(v: BigInteger): String = MAPPER.writeValueAsString(mapOf(v to 0))
9095

9196
@Test

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@ import kotlin.test.assertEquals
1010
class TestGithub101_JacksonInjectTest {
1111
@Test
1212
fun `JacksonInject-annotated parameters are populated when constructing Kotlin data classes`() {
13-
val mapper = jacksonObjectMapper()
1413
val contextualValue = UUID.randomUUID()
15-
assertEquals(SomeDatum("test", contextualValue),
16-
mapper.readerFor(SomeDatum::class.java)
17-
.with(InjectableValues.Std(mapOf("context" to contextualValue)))
18-
.readValue("""{ "value": "test" }"""))
14+
val reader = jacksonObjectMapper()
15+
.readerFor(SomeDatum::class.java)
16+
.with(InjectableValues.Std(mapOf("context" to contextualValue)))
17+
assertEquals(
18+
SomeDatum("test", contextualValue),
19+
reader.readValue("""{ "value": "test" }""")
20+
)
1921
}
2022

2123
data class SomeDatum(val value: String, @JacksonInject("context") val contextualValue: UUID)
22-
}
24+
}

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

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

33
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
4+
import org.junit.jupiter.api.Nested
45
import org.junit.jupiter.api.Test
56
import kotlin.test.assertEquals
67

@@ -32,7 +33,8 @@ class TestGithub148 {
3233
val type: IncorrectType
3334
)
3435

35-
class DemoApplicationTests {
36+
@Nested
37+
inner class DemoApplicationTests {
3638
val objectMapper = jacksonObjectMapper()
3739

3840
@Test
@@ -45,4 +47,4 @@ class TestGithub148 {
4547
assertEquals("{\"name\":\"incorrent\",\"type\":\"TYPEA\"}", objectMapper.writeValueAsString(IncorrentBean("incorrent", IncorrectType.TYPEA)))
4648
}
4749
}
48-
}
50+
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class TestGithub168 {
1313
class TestClass(@JsonProperty(value = "foo", required = true) foo: String?, val baz: String)
1414

1515
@Test
16-
fun testIfRequiredIsReallyRequiredWhenNullused() {
16+
fun testIfRequiredIsReallyRequiredWhenNullUsed() {
1717
val obj = jacksonObjectMapper().readValue<TestClass>("""{"foo":null,"baz":"whatever"}""")
1818
assertEquals("whatever", obj.baz)
1919
}
@@ -27,7 +27,7 @@ class TestGithub168 {
2727
}
2828

2929
@Test
30-
fun testIfRequiredIsReallyRequiredWhenVauePresent() {
30+
fun testIfRequiredIsReallyRequiredWhenValuePresent() {
3131
val obj = jacksonObjectMapper().readValue<TestClass>("""{"foo":"yay!","baz":"whatever"}""")
3232
assertEquals("whatever", obj.baz)
3333
}

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@ import com.fasterxml.jackson.annotation.JsonProperty
66
import com.fasterxml.jackson.databind.InjectableValues
77
import com.fasterxml.jackson.databind.ObjectMapper
88
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
9-
import kotlin.math.exp
109
import org.junit.jupiter.api.Test
1110
import kotlin.test.assertEquals
12-
import kotlin.test.assertNotEquals
1311

1412
class Github722 {
1513
data class FailingDto @JsonCreator constructor(
@@ -39,11 +37,13 @@ class Github722 {
3937
@Test
4038
fun failing() {
4139
// The kotlin mapper uses the Kotlin default value instead of the Inject value.
42-
val kotlinMapper = jacksonObjectMapper()
43-
val result = kotlinMapper.readerFor(FailingDto::class.java)
40+
val reader = jacksonObjectMapper()
41+
.readerFor(FailingDto::class.java)
4442
.with(InjectableValues.Std(injectValues))
45-
.readValue<FailingDto>("{}")
43+
val result = reader.readValue<FailingDto>("{}")
4644

45+
// fixed
46+
// assertNotEquals(result, expected, "GitHubXXX fixed.")
4747
assertEquals(expected, result)
4848
}
4949

@@ -56,10 +56,10 @@ class Github722 {
5656

5757
@Test
5858
fun withoutDefaultValue() {
59-
val kotlinMapper = jacksonObjectMapper()
60-
val result = kotlinMapper.readerFor(WithoutDefaultValue::class.java)
59+
val reader = jacksonObjectMapper()
60+
.readerFor(WithoutDefaultValue::class.java)
6161
.with(InjectableValues.Std(injectValues))
62-
.readValue<WithoutDefaultValue>("{}")
62+
val result = reader.readValue<WithoutDefaultValue>("{}")
6363

6464
// If there is no default value, the problem does not occur.
6565
assertEquals(WithoutDefaultValue(1, 2), result)

0 commit comments

Comments
 (0)