11package io.github.projectmapk.jackson.module.kogera.zIntegration.deser.valueClass
22
3+ import io.github.projectmapk.jackson.module.kogera.defaultMapper
34import io.github.projectmapk.jackson.module.kogera.jacksonObjectMapper
45import io.github.projectmapk.jackson.module.kogera.readValue
6+ import org.junit.jupiter.api.Assertions
57import org.junit.jupiter.api.Assertions.assertEquals
6- import org.junit.jupiter.api.Assertions.assertTrue
8+ import org.junit.jupiter.api.Nested
79import org.junit.jupiter.api.Test
810import org.junit.jupiter.api.assertThrows
911import java.lang.reflect.InvocationTargetException
1012
11- class NoSpecifiedTest {
13+ class WithoutCustomDeserializeMethodTest {
1214 companion object {
1315 val mapper = jacksonObjectMapper()
1416 val throwable = IllegalArgumentException (" test" )
1517 }
1618
19+ @Nested
20+ inner class DirectDeserializeTest {
21+ @Test
22+ fun primitive () {
23+ val result = defaultMapper.readValue<Primitive >(" 1" )
24+ assertEquals(Primitive (1 ), result)
25+ }
26+
27+ @Test
28+ fun nonNullObject () {
29+ val result = defaultMapper.readValue<NonNullObject >(""" "foo"""" )
30+ assertEquals(NonNullObject (" foo" ), result)
31+ }
32+
33+ @Suppress(" ClassName" )
34+ @Nested
35+ inner class NullableObject_ {
36+ @Test
37+ fun value () {
38+ val result = defaultMapper.readValue<NullableObject >(""" "foo"""" )
39+ assertEquals(NullableObject (" foo" ), result)
40+ }
41+
42+ // failing
43+ @Test
44+ fun nullString () {
45+ assertThrows<NullPointerException >(" #209 has been fixed." ) {
46+ val result = defaultMapper.readValue<NullableObject >(" null" )
47+ assertEquals(NullableObject (null ), result)
48+ }
49+ }
50+ }
51+ }
52+
1753 data class Dst (
1854 val pNn : Primitive ,
1955 val pN : Primitive ? ,
@@ -24,7 +60,7 @@ class NoSpecifiedTest {
2460 )
2561
2662 @Test
27- fun nonNull () {
63+ fun withoutNull () {
2864 val expected = Dst (
2965 Primitive (1 ),
3066 Primitive (2 ),
@@ -56,15 +92,17 @@ class NoSpecifiedTest {
5692 }
5793
5894 @JvmInline
59- value class HasCheck (val value : Int ) {
95+ value class HasCheckConstructor (val value : Int ) {
6096 init {
6197 if (value < 0 ) throw throwable
6298 }
6399 }
64100
65101 @Test
66- fun callCheckTest () {
67- val e = assertThrows<InvocationTargetException > { mapper .readValue<HasCheck >(" -1" ) }
68- assertTrue(e.cause == = throwable)
102+ fun callConstructorCheckTest () {
103+ val e = assertThrows<InvocationTargetException > { defaultMapper .readValue<HasCheckConstructor >(" -1" ) }
104+ Assertions . assertTrue(e.cause == = throwable)
69105 }
106+
107+ // If all JsonCreator tests are OK, no need to check throws from factory functions.
70108}
0 commit comments