From b7093e1be7ab8c487d62c0f5d926fc3809c46414 Mon Sep 17 00:00:00 2001 From: wrongwrong Date: Sun, 7 Jan 2024 19:01:39 +0900 Subject: [PATCH] Add ArgumentBucket test --- .../module/kotlin/ArgumentBucketTest.kt | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 src/test/kotlin/com/fasterxml/jackson/module/kotlin/ArgumentBucketTest.kt diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/ArgumentBucketTest.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/ArgumentBucketTest.kt new file mode 100644 index 00000000..20155690 --- /dev/null +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/ArgumentBucketTest.kt @@ -0,0 +1,86 @@ +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 kotlin.reflect.KFunction +import kotlin.reflect.full.functions +import kotlin.reflect.full.hasAnnotation +import kotlin.test.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) + + @Test + fun constructorTest() { + val function: KFunction<*> = ::Constructor + val params = function.parameters + val generator = BucketGenerator.forConstructor(params.size) + val bucket = generator.generate() + + assertTrue(bucket.isEmpty()) + assertEquals(0, bucket.size) + assertFalse(bucket.isFullInitialized) + + bucket[params[0]] = "foo" + + assertFalse(bucket.isEmpty()) + assertEquals(1, bucket.size) + assertFalse(bucket.isFullInitialized) + assertEquals("foo", bucket[params[0]]) + + bucket[params[1]] = "bar" + + assertFalse(bucket.isEmpty()) + assertEquals(2, bucket.size) + assertTrue(bucket.isFullInitialized) + 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() } + val params = function.parameters + val generator = BucketGenerator.forMethod(params.size, params[0], Method) + val bucket = generator.generate() + + assertFalse(bucket.isEmpty()) + assertEquals(1, bucket.size) + assertEquals(Method.Companion, bucket[params[0]]) + assertFalse(bucket.isFullInitialized) + + bucket[params[1]] = "foo" + + assertFalse(bucket.isEmpty()) + assertEquals(2, bucket.size) + assertFalse(bucket.isFullInitialized) + assertEquals("foo", bucket[params[1]]) + + bucket[params[2]] = "bar" + + assertFalse(bucket.isEmpty()) + assertEquals(3, bucket.size) + assertTrue(bucket.isFullInitialized) + assertEquals("bar", bucket[params[2]]) + } + } + + // After support, add a case with a value class. +}