Skip to content

Commit c3a056f

Browse files
committed
Fix tests
1 parent ac32eb8 commit c3a056f

File tree

5 files changed

+23
-39
lines changed

5 files changed

+23
-39
lines changed

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

Lines changed: 0 additions & 20 deletions
This file was deleted.

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

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

33
import com.fasterxml.jackson.databind.ObjectMapper
4+
import com.fasterxml.jackson.databind.exc.MismatchedInputException
45
import com.fasterxml.jackson.module.kotlin.KotlinFeature.NullIsSameAsDefault
5-
import com.fasterxml.jackson.module.kotlin.MissingKotlinParameterException
66
import com.fasterxml.jackson.module.kotlin.kotlinModule
77
import com.fasterxml.jackson.module.kotlin.readValue
88
import org.junit.Assert
@@ -139,7 +139,7 @@ class TestNullToDefault {
139139
Assert.assertEquals(true, item.canBeProcessed)
140140
}
141141

142-
@Test(expected = MissingKotlinParameterException::class)
142+
@Test(expected = MismatchedInputException::class)
143143
fun shouldThrowExceptionWhenProvidedNullForNotNullFieldWithoutDefault() {
144144
createMapper(true).readValue<TestClass>(
145145
"""{

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

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

33
import com.fasterxml.jackson.databind.ObjectMapper
4+
import com.fasterxml.jackson.databind.exc.MismatchedInputException
45
import com.fasterxml.jackson.module.kotlin.KotlinFeature.StrictNullChecks
5-
import com.fasterxml.jackson.module.kotlin.MissingKotlinParameterException
66
import com.fasterxml.jackson.module.kotlin.kotlinModule
77
import com.fasterxml.jackson.module.kotlin.readValue
88
import org.hamcrest.CoreMatchers.equalTo
@@ -27,7 +27,7 @@ class StrictNullChecksTest {
2727

2828
private data class ClassWithListOfInt(val samples: List<Int>)
2929

30-
@Test(expected = MissingKotlinParameterException::class)
30+
@Test(expected = MismatchedInputException::class)
3131
fun testListOfInt() {
3232
val json = """{"samples":[1, null]}"""
3333
mapper.readValue<ClassWithListOfInt>(json)
@@ -55,7 +55,7 @@ class StrictNullChecksTest {
5555

5656
private data class ClassWithArrayOfInt(val samples: Array<Int>)
5757

58-
@Test(expected = MissingKotlinParameterException::class)
58+
@Test(expected = MismatchedInputException::class)
5959
fun testArrayOfInt() {
6060
val json = """{"samples":[1, null]}"""
6161
mapper.readValue<ClassWithArrayOfInt>(json)
@@ -83,7 +83,7 @@ class StrictNullChecksTest {
8383

8484
private data class ClassWithMapOfStringToInt(val samples: Map<String, Int>)
8585

86-
@Test(expected = MissingKotlinParameterException::class)
86+
@Test(expected = MismatchedInputException::class)
8787
fun testMapOfStringToIntWithNullValue() {
8888
val json = """{ "samples": { "key": null } }"""
8989
mapper.readValue<ClassWithMapOfStringToInt>(json)
@@ -110,7 +110,7 @@ class StrictNullChecksTest {
110110
}
111111

112112
@Ignore // this is a hard problem to solve and is currently not addressed
113-
@Test(expected = MissingKotlinParameterException::class)
113+
@Test(expected = MismatchedInputException::class)
114114
fun testListOfGenericWithNullValue() {
115115
val json = """{"samples":[1, null]}"""
116116
mapper.readValue<TestClass<List<Int>>>(json)
@@ -124,7 +124,7 @@ class StrictNullChecksTest {
124124
}
125125

126126
@Ignore // this is a hard problem to solve and is currently not addressed
127-
@Test(expected = MissingKotlinParameterException::class)
127+
@Test(expected = MismatchedInputException::class)
128128
fun testMapOfGenericWithNullValue() {
129129
val json = """{ "samples": { "key": null } }"""
130130
mapper.readValue<TestClass<Map<String, Int>>>(json)
@@ -138,7 +138,7 @@ class StrictNullChecksTest {
138138
}
139139

140140
@Ignore // this is a hard problem to solve and is currently not addressed
141-
@Test(expected = MissingKotlinParameterException::class)
141+
@Test(expected = MismatchedInputException::class)
142142
fun testArrayOfGenericWithNullValue() {
143143
val json = """{"samples":[1, null]}"""
144144
mapper.readValue<TestClass<Array<Int>>>(json)

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
@@ -1,7 +1,7 @@
11
package com.fasterxml.jackson.module.kotlin.test.github
22

33
import com.fasterxml.jackson.annotation.JsonProperty
4-
import com.fasterxml.jackson.module.kotlin.MissingKotlinParameterException
4+
import com.fasterxml.jackson.databind.exc.MismatchedInputException
55
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
66
import com.fasterxml.jackson.module.kotlin.readValue
77
import org.junit.Test
@@ -17,7 +17,7 @@ class TestGithub168 {
1717
assertEquals("whatever", obj.baz)
1818
}
1919

20-
@Test(expected = MissingKotlinParameterException::class)
20+
@Test(expected = MismatchedInputException::class)
2121
fun testIfRequiredIsReallyRequiredWhenAbsent() {
2222
val obj = jacksonObjectMapper().readValue<TestClass>("""{"baz":"whatever"}""")
2323
assertEquals("whatever", obj.baz)

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

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

33
import com.fasterxml.jackson.databind.JsonMappingException
4-
import com.fasterxml.jackson.module.kotlin.MissingKotlinParameterException
4+
import com.fasterxml.jackson.databind.exc.MismatchedInputException
55
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
66
import com.fasterxml.jackson.module.kotlin.readValue
77
import org.hamcrest.CustomTypeSafeMatcher
@@ -106,16 +106,20 @@ private data class Crowd(val people: List<Person>)
106106

107107
private fun missingFirstNameParameter() = missingConstructorParam(::Person.parameters[0])
108108

109-
private fun missingConstructorParam(param: KParameter) = object : CustomTypeSafeMatcher<MissingKotlinParameterException>("MissingKotlinParameterException with missing `${param.name}` parameter") {
110-
override fun matchesSafely(e: MissingKotlinParameterException): Boolean = e.parameter.equals(param)
109+
private fun missingConstructorParam(
110+
param: KParameter
111+
) = object : CustomTypeSafeMatcher<MismatchedInputException>(
112+
"MissingKotlinParameterException with missing `${param.name}` parameter"
113+
) {
114+
override fun matchesSafely(e: MismatchedInputException): Boolean = param.name == e.path.last().fieldName
111115
}
112116

113-
private fun pathMatches(path: String) = object : CustomTypeSafeMatcher<MissingKotlinParameterException>("MissingKotlinParameterException with path `$path`") {
114-
override fun matchesSafely(e: MissingKotlinParameterException): Boolean = e.getHumanReadablePath().equals(path)
117+
private fun pathMatches(path: String) = object : CustomTypeSafeMatcher<MismatchedInputException>("MissingKotlinParameterException with path `$path`") {
118+
override fun matchesSafely(e: MismatchedInputException): Boolean = e.getHumanReadablePath().equals(path)
115119
}
116120

117-
private fun location(line: Int, column: Int) = object : CustomTypeSafeMatcher<MissingKotlinParameterException>("MissingKotlinParameterException with location (line=$line, column=$column)") {
118-
override fun matchesSafely(e: MissingKotlinParameterException): Boolean {
121+
private fun location(line: Int, column: Int) = object : CustomTypeSafeMatcher<MismatchedInputException>("MissingKotlinParameterException with location (line=$line, column=$column)") {
122+
override fun matchesSafely(e: MismatchedInputException): Boolean {
119123
return e.location != null && line.equals(e.location.lineNr) && column.equals(e.location.columnNr)
120124
}
121125
}
@@ -131,4 +135,4 @@ private fun JsonMappingException.getHumanReadablePath(): String {
131135
}
132136
}
133137
return builder.toString()
134-
}
138+
}

0 commit comments

Comments
 (0)