Skip to content

Commit

Permalink
Merge remote-tracking branch 'FasterXML/2.19'
Browse files Browse the repository at this point in the history
  • Loading branch information
k163377 committed Dec 8, 2024
2 parents bed5828 + 2ee6fe9 commit 27b9977
Show file tree
Hide file tree
Showing 142 changed files with 760 additions and 828 deletions.
15 changes: 13 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,26 @@

<!-- only for testing... -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test-junit</artifactId>
<version>${version.kotlin}</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>tools.jackson.dataformat</groupId>
Expand Down
1 change: 1 addition & 0 deletions release-notes/CREDITS-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Contributors:
# 2.19.0 (not yet released)

WrongWrong (@k163377)
* #866: Upgrade to JUnit5
* #861: Update Kotlin to 1.9.24
* #858: Refactor findDefaultCreator
* #839: Remove useKotlinPropertyNameForGetter and unify with kotlinPropertyNameAsImplicitName
Expand Down
33 changes: 14 additions & 19 deletions src/test/kotlin/tools/jackson/module/kotlin/ArgumentBucketTest.kt
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
package tools.jackson.module.kotlin

import com.fasterxml.jackson.annotation.JsonCreator
import org.junit.Ignore
import org.junit.experimental.runners.Enclosed
import org.junit.runner.RunWith
import org.junit.jupiter.api.Nested
import kotlin.reflect.KFunction
import kotlin.reflect.full.functions
import kotlin.reflect.full.hasAnnotation
import kotlin.test.Test
import org.junit.jupiter.api.Test
import kotlin.test.assertEquals
import kotlin.test.assertFalse
import kotlin.test.assertTrue


@RunWith(Enclosed::class)
class ArgumentBucketTest {
class Normal {
@Ignore
data class Constructor(val foo: String, val bar: String)
data class Constructor(val foo: String, val bar: String)

data class Method(val foo: String, val bar: String) {
companion object {
@JvmStatic
@JsonCreator
fun of(foo: String, bar: String): Method = Method(foo, bar)
}
}

@Nested
inner class Normal {
@Test
fun constructorTest() {
val function: KFunction<*> = Normal::Constructor
val function: KFunction<*> = ::Constructor
val params = function.parameters
val generator = BucketGenerator.forConstructor(params.size)
val bucket = generator.generate()
Expand All @@ -45,15 +49,6 @@ class ArgumentBucketTest {
assertEquals("bar", bucket[params[1]])
}

@Ignore
data class Method(val foo: String, val bar: String) {
companion object {
@JvmStatic
@JsonCreator
fun of(foo: String, bar: String): Method = Method(foo, bar)
}
}

@Test
fun methodTest() {
val function: KFunction<*> = Method.Companion::class.functions.first { it.hasAnnotation<JsonCreator>() }
Expand Down
4 changes: 2 additions & 2 deletions src/test/kotlin/tools/jackson/module/kotlin/DslTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import tools.jackson.module.kotlin.KotlinFeature.NullToEmptyCollection
import tools.jackson.module.kotlin.KotlinFeature.NullToEmptyMap
import tools.jackson.module.kotlin.KotlinFeature.SingletonSupport
import tools.jackson.module.kotlin.KotlinFeature.StrictNullChecks
import org.junit.Assert.assertNotNull
import org.junit.Test
import org.junit.jupiter.api.Assertions.assertNotNull
import org.junit.jupiter.api.Test
import kotlin.test.assertEquals
import kotlin.test.assertFalse
import kotlin.test.assertTrue
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package tools.jackson.module.kotlin

import junit.framework.TestCase
import org.junit.jupiter.api.Assertions.fail
import java.io.ByteArrayInputStream
import java.io.ByteArrayOutputStream
import java.io.ObjectInputStream
Expand All @@ -14,14 +14,13 @@ fun jdkSerialize(o: Any): ByteArray {
return bytes.toByteArray()
}

fun <T> jdkDeserialize(raw: ByteArray): T? {
fun <T> jdkDeserialize(raw: ByteArray): T {
val objIn = ObjectInputStream(ByteArrayInputStream(raw))
return try {
@Suppress("UNCHECKED_CAST")
objIn.readObject() as T
} catch (e: ClassNotFoundException) {
TestCase.fail("Missing class: " + e.message)
null
fail("Missing class: " + e.message)
} finally {
objIn.close()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package tools.jackson.module.kotlin

import tools.jackson.databind.deser.std.StdValueInstantiator
import org.junit.Assert.assertEquals
import org.junit.Assert.assertThrows
import org.junit.Assert.assertTrue
import org.junit.Test
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.Test

class KotlinInstantiatorsTest {
private val mapper = jacksonObjectMapper()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package tools.jackson.module.kotlin

import tools.jackson.module.kotlin.KotlinFeature.*
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test
import tools.jackson.databind.json.JsonMapper
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertFalse
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Test
import kotlin.test.assertNotNull

class KotlinModuleTest {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package tools.jackson.module.kotlin

import org.junit.Test
import org.junit.jupiter.api.Test
import kotlin.test.assertNotNull
import kotlin.test.assertNull

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package tools.jackson.module.kotlin

import org.junit.Test
import org.junit.jupiter.api.Test
import kotlin.test.assertNotNull

class ReflectionCacheTest {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package tools.jackson.module.kotlin.kogeraIntegration.deser.valueClass

import com.fasterxml.jackson.annotation.JacksonInject
import org.junit.Assert.assertEquals
import org.junit.Assert.assertThrows
import org.junit.Test
import tools.jackson.databind.InjectableValues
import tools.jackson.databind.MapperFeature
import tools.jackson.module.kotlin.jacksonMapperBuilder
import tools.jackson.module.kotlin.jacksonObjectMapper
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertThrows
import org.junit.jupiter.api.Test

class JacksonInjectTest {
// This is specified as a getter because there is a possibility of problems if it is assigned to a field.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import tools.jackson.module.kotlin.WrapsNullableValueClassDeserializer
import tools.jackson.module.kotlin.jacksonObjectMapper
import tools.jackson.module.kotlin.readValue
import kotlin.reflect.jvm.internal.KotlinReflectionInternalError
import org.junit.Assert.assertEquals
import org.junit.Assert.assertThrows
import org.junit.Test
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows

class NullableObjectEdgeCases {
@JvmInline
Expand Down Expand Up @@ -61,7 +61,7 @@ class NullableObjectEdgeCases {
// There is a problem with #51, so it is a failing test.
@Test
fun `Nulls_SKIP works`() {
assertThrows("#761(KT-57357) fixed", KotlinReflectionInternalError::class.java) {
assertThrows<KotlinReflectionInternalError>("#761(KT-57357) fixed") {
val result = jacksonObjectMapper().readValue<NullsSkip>("""{"nn":null,"n":null}""")
assertEquals(NullValue(VC("skip"), VC("skip")), result)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,21 @@ package tools.jackson.module.kotlin.kogeraIntegration.deser.valueClass
import tools.jackson.module.kotlin.defaultMapper
import tools.jackson.module.kotlin.jacksonObjectMapper
import tools.jackson.module.kotlin.readValue
import org.junit.Assert.assertEquals
import org.junit.Assert.assertThrows
import org.junit.Assert.assertTrue
import org.junit.Ignore
import org.junit.experimental.runners.Enclosed
import org.junit.runner.RunWith
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Nested
import org.junit.jupiter.api.assertThrows
import org.junit.jupiter.api.Test
import java.lang.reflect.InvocationTargetException
import kotlin.test.Test

@RunWith(Enclosed::class)
class WithoutCustomDeserializeMethodTest {
@Ignore
companion object {
val mapper = jacksonObjectMapper()
val throwable = IllegalArgumentException("test")
}

class DirectDeserializeTest {
@Nested
inner class DirectDeserializeTest {
@Test
fun primitive() {
val result = defaultMapper.readValue<Primitive>("1")
Expand All @@ -34,7 +31,8 @@ class WithoutCustomDeserializeMethodTest {
}

@Suppress("ClassName")
class NullableObject_ {
@Nested
inner class NullableObject_ {
@Test
fun value() {
val result = defaultMapper.readValue<NullableObject>(""""foo"""")
Expand All @@ -44,32 +42,14 @@ class WithoutCustomDeserializeMethodTest {
// failing
@Test
fun nullString() {
// #209 has been fixed.
assertThrows(NullPointerException::class.java) {
org.junit.jupiter.api.assertThrows<NullPointerException>("#209 has been fixed.") {
val result = defaultMapper.readValue<NullableObject>("null")
assertEquals(NullableObject(null), result)
}
}
}

@Ignore
@JvmInline
value class HasCheckConstructor(val value: Int) {
init {
if (value < 0) throw throwable
}
}

@Test
fun callConstructorCheckTest() {
val e = assertThrows(InvocationTargetException::class.java) {
defaultMapper.readValue<HasCheckConstructor>("-1")
}
assertTrue(e.cause === throwable)
}
}

@Ignore
data class Dst(
val pNn: Primitive,
val pN: Primitive?,
Expand All @@ -79,39 +59,50 @@ class WithoutCustomDeserializeMethodTest {
val noN: NullableObject?
)

class InParameterDeserialize {
@Test
fun withoutNull() {
val expected = Dst(
Primitive(1),
Primitive(2),
NonNullObject("foo"),
NonNullObject("bar"),
NullableObject("baz"),
NullableObject("qux")
)
val src = mapper.writeValueAsString(expected)
val result = mapper.readValue<Dst>(src)
@Test
fun withoutNull() {
val expected = Dst(
Primitive(1),
Primitive(2),
NonNullObject("foo"),
NonNullObject("bar"),
NullableObject("baz"),
NullableObject("qux")
)
val src = mapper.writeValueAsString(expected)
val result = mapper.readValue<Dst>(src)

assertEquals(expected, result)
}
assertEquals(expected, result)
}

@Test
fun withNull() {
val expected = Dst(
Primitive(1),
null,
NonNullObject("foo"),
null,
NullableObject(null),
null
)
val src = mapper.writeValueAsString(expected)
val result = mapper.readValue<Dst>(src)
@Test
fun withNull() {
val expected = Dst(
Primitive(1),
null,
NonNullObject("foo"),
null,
NullableObject(null),
null
)
val src = mapper.writeValueAsString(expected)
val result = mapper.readValue<Dst>(src)

assertEquals(expected, result)
assertEquals(expected, result)
}

@JvmInline
value class HasCheckConstructor(val value: Int) {
init {
if (value < 0) throw throwable
}
}

@Test
fun callConstructorCheckTest() {
val e = assertThrows<InvocationTargetException> { defaultMapper.readValue<HasCheckConstructor>("-1") }
assertTrue(e.cause === throwable)
}

// If all JsonCreator tests are OK, no need to check throws from factory functions.
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import com.fasterxml.jackson.annotation.JsonCreator
import tools.jackson.module.kotlin.jacksonObjectMapper
import tools.jackson.module.kotlin.kogeraIntegration.deser.valueClass.NonNullObject
import tools.jackson.module.kotlin.readValue
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test

class NonNullObjectTest {
companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import com.fasterxml.jackson.annotation.JsonCreator
import tools.jackson.module.kotlin.jacksonObjectMapper
import tools.jackson.module.kotlin.readValue
import tools.jackson.module.kotlin.kogeraIntegration.deser.valueClass.NullableObject
import org.junit.Assert.assertEquals
import org.junit.Assert.assertThrows
import kotlin.test.Test
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertThrows
import org.junit.jupiter.api.Test

class NullableObjectTest {
companion object {
Expand Down
Loading

0 comments on commit 27b9977

Please sign in to comment.