Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
dee7e97
Upgrade to JUnit5
k163377 Dec 8, 2024
9a6ceb3
Replace @Test(expected = ... with assertThorws
k163377 Dec 8, 2024
4611f22
Replace kotlin.test.Test with org.junit.jupiter.api.Test
k163377 Dec 8, 2024
c27440c
Replace @Rule with assertThrows
k163377 Dec 8, 2024
5f5beec
Replace @Rule with assertThrows
k163377 Dec 8, 2024
874cbde
Remove use of @Before
k163377 Dec 8, 2024
4d267fc
Migrate to JUnit5 notation and remove use of @Ignore
k163377 Dec 8, 2024
de55aad
Migrate to JUnit5 notation and remove use of @Ignore
k163377 Dec 8, 2024
bdff599
Migrate to JUnit5 notation and remove use of @Ignore
k163377 Dec 8, 2024
56ffadc
Remove use of @Ignore
k163377 Dec 8, 2024
277ae27
Migrate to JUnit5 notation
k163377 Dec 8, 2024
398387e
Migrate to JUnit5 notation
k163377 Dec 8, 2024
b36abe1
Migrate to JUnit5 notation
k163377 Dec 8, 2024
822d654
Migrate to JUnit5 notation
k163377 Dec 8, 2024
5a199ee
Replace org.junit.Test with org.junit.jupiter.api.Test
k163377 Dec 8, 2024
93f230f
Migrate to JUnit5 notation
k163377 Dec 8, 2024
722c37b
Replace org.junit.Assert with org.junit.jupiter.api.Assertions
k163377 Dec 8, 2024
5ff39e7
Migrate to JUnit5 notation
k163377 Dec 8, 2024
d4070a7
Migrate to JUnit5 notation
k163377 Dec 8, 2024
b8931e8
Replace junit.framework.TestCase with org.junit.jupiter.api.Assertions
k163377 Dec 8, 2024
c695766
Migrate to JUnit5 notation
k163377 Dec 8, 2024
1e881c8
Migrate to JUnit5 notation
k163377 Dec 8, 2024
52ae8cf
Migrate to JUnit5 notation
k163377 Dec 8, 2024
0777195
Migrate to JUnit5 notation
k163377 Dec 8, 2024
cabf39d
Migrate to JUnit5 notation
k163377 Dec 8, 2024
11e42dd
Migrate to JUnit5 notation
k163377 Dec 8, 2024
0a39f2f
Migrate to JUnit5 notation
k163377 Dec 8, 2024
881722f
Migrate to JUnit5 notation
k163377 Dec 8, 2024
98b3e6f
Migrate to JUnit5 notation
k163377 Dec 8, 2024
b5c8d4d
Migrate to JUnit5 notation
k163377 Dec 8, 2024
ff37577
Migrate to JUnit5 notation
k163377 Dec 8, 2024
7334f47
Migrate to JUnit5 notation
k163377 Dec 8, 2024
140745c
Migrate to JUnit5 notation
k163377 Dec 8, 2024
009671d
Exclude JUnit4
k163377 Dec 8, 2024
c50c884
Update release notes wrt #866
k163377 Dec 8, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>com.fasterxml.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
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
package com.fasterxml.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<*> = ::Constructor
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import com.fasterxml.jackson.module.kotlin.KotlinFeature.NullToEmptyCollection
import com.fasterxml.jackson.module.kotlin.KotlinFeature.NullToEmptyMap
import com.fasterxml.jackson.module.kotlin.KotlinFeature.SingletonSupport
import com.fasterxml.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 com.fasterxml.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,8 +1,8 @@
package com.fasterxml.jackson.module.kotlin

import com.fasterxml.jackson.databind.deser.std.StdValueInstantiator
import org.junit.Assert.*
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
Expand Up @@ -2,10 +2,10 @@ package com.fasterxml.jackson.module.kotlin

import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.KotlinFeature.*
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test
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 com.fasterxml.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 com.fasterxml.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
Expand Up @@ -3,9 +3,9 @@ package com.fasterxml.jackson.module.kotlin.kogeraIntegration.deser.valueClass
import com.fasterxml.jackson.annotation.JacksonInject
import com.fasterxml.jackson.databind.InjectableValues
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
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.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 com.fasterxml.jackson.module.kotlin.WrapsNullableValueClassDeserializer
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.fasterxml.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 com.fasterxml.jackson.module.kotlin.kogeraIntegration.deser.valueClass
import com.fasterxml.jackson.module.kotlin.defaultMapper
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.fasterxml.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 com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.fasterxml.jackson.module.kotlin.kogeraIntegration.deser.valueClass.NonNullObject
import com.fasterxml.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 com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.fasterxml.jackson.module.kotlin.readValue
import com.fasterxml.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
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import com.fasterxml.jackson.annotation.JsonCreator
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.fasterxml.jackson.module.kotlin.kogeraIntegration.deser.valueClass.Primitive
import com.fasterxml.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 PrimitiveTest {
companion object {
Expand Down
Loading