Skip to content

Commit 9838ab4

Browse files
committed
Update test to to work with #521
1 parent fade3f6 commit 9838ab4

File tree

1 file changed

+27
-13
lines changed

1 file changed

+27
-13
lines changed
Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package com.fasterxml.jackson.module.kotlin
22

33
import com.fasterxml.jackson.databind.deser.std.StdValueInstantiator
4-
import org.junit.Assert.assertEquals
5-
import org.junit.Assert.assertTrue
4+
import org.junit.Assert.*
65
import org.junit.Test
76

87
class KotlinInstantiatorsTest {
98
private val mapper = jacksonObjectMapper()
9+
private val deserConfig = mapper.deserializationConfig
1010

1111
private val kotlinInstantiators = KotlinInstantiators(
1212
ReflectionCache(10),
@@ -16,19 +16,13 @@ class KotlinInstantiatorsTest {
1616
strictNullChecks = false
1717
)
1818

19-
private class DefaultClass
20-
21-
private val deserConfig = mapper.deserializationConfig
22-
private val defaultInstantiator = object : StdValueInstantiator(
23-
deserConfig,
24-
mapper.constructType(DefaultClass::class.java)
25-
) {}
26-
2719
@Test
2820
fun `Provides default instantiator for Java class`() {
21+
val javaType = mapper.constructType(String::class.java)
22+
val defaultInstantiator = StdValueInstantiator(deserConfig, javaType)
2923
val instantiator = kotlinInstantiators.findValueInstantiator(
3024
deserConfig,
31-
deserConfig.introspect(mapper.constructType(String::class.java)),
25+
deserConfig.introspect(javaType),
3226
defaultInstantiator
3327
)
3428

@@ -39,13 +33,33 @@ class KotlinInstantiatorsTest {
3933
fun `Provides KotlinValueInstantiator for Kotlin class`() {
4034
class TestClass
4135

36+
val javaType = mapper.constructType(TestClass::class.java)
4237
val instantiator = kotlinInstantiators.findValueInstantiator(
4338
deserConfig,
44-
deserConfig.introspect(mapper.constructType(TestClass::class.java)),
45-
defaultInstantiator
39+
deserConfig.introspect(javaType),
40+
StdValueInstantiator(deserConfig, javaType)
4641
)
4742

4843
assertTrue(instantiator is StdValueInstantiator)
4944
assertTrue(instantiator::class == KotlinValueInstantiator::class)
5045
}
46+
47+
@Test
48+
fun `Throws for Kotlin class when default instantiator isn't StdValueInstantiator`() {
49+
class TestClass
50+
class DefaultClass
51+
52+
val subClassInstantiator = object : StdValueInstantiator(
53+
deserConfig,
54+
mapper.constructType(DefaultClass::class.java)
55+
) {}
56+
57+
assertThrows(IllegalStateException::class.java) {
58+
kotlinInstantiators.findValueInstantiator(
59+
deserConfig,
60+
deserConfig.introspect(mapper.constructType(TestClass::class.java)),
61+
subClassInstantiator
62+
)
63+
}
64+
}
5165
}

0 commit comments

Comments
 (0)