Skip to content

Commit 3089e92

Browse files
committed
add call test for MethodValueCreator
1 parent 33b46ba commit 3089e92

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,13 @@
111111
<artifactId>jackson-dataformat-xml</artifactId>
112112
<scope>test</scope>
113113
</dependency>
114+
<!-- https://mvnrepository.com/artifact/io.mockk/mockk -->
115+
<dependency>
116+
<groupId>io.mockk</groupId>
117+
<artifactId>mockk</artifactId>
118+
<version>1.12.2</version>
119+
<scope>test</scope>
120+
</dependency>
114121
</dependencies>
115122

116123
<build>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.fasterxml.jackson.module.kotlin
2+
3+
import io.mockk.spyk
4+
import io.mockk.verify
5+
import org.junit.Test
6+
import kotlin.reflect.KFunction
7+
import kotlin.reflect.full.functions
8+
import kotlin.test.assertEquals
9+
10+
class MethodValueCreatorTest {
11+
data class Data(val value: Int) {
12+
companion object {
13+
fun target(value: Int = -1) = Data(value)
14+
}
15+
}
16+
17+
companion object {
18+
private val targetFunction: KFunction<*> = spyk(Data.Companion::class.functions.first { it.name == "target" })
19+
private val methodValueCreator = MethodValueCreator.of(targetFunction)!!
20+
}
21+
22+
@Test
23+
fun withDefaultValue() {
24+
val actual = methodValueCreator.generateBucket().let { methodValueCreator.callBy(it) }
25+
assertEquals(Data(-1), actual)
26+
verify(exactly = 1) { targetFunction.callBy(any()) }
27+
}
28+
29+
@Test
30+
fun withoutDefaultValue() {
31+
val actual = methodValueCreator.generateBucket().let {
32+
it[1] = 1
33+
methodValueCreator.callBy(it)
34+
}
35+
assertEquals(Data(1), actual)
36+
// If the argument is fully initialized, call is used instead of callBy
37+
verify(exactly = 1) { targetFunction.call(*anyVararg()) }
38+
verify(exactly = 0) { targetFunction.callBy(any()) }
39+
}
40+
}

0 commit comments

Comments
 (0)