-
Notifications
You must be signed in to change notification settings - Fork 175
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
86 additions
and
0 deletions.
There are no files selected for viewing
86 changes: 86 additions & 0 deletions
86
src/test/kotlin/com/fasterxml/jackson/module/kotlin/ArgumentBucketTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<JsonCreator>() } | ||
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. | ||
} |