File tree Expand file tree Collapse file tree 2 files changed +47
-0
lines changed
src/test/kotlin/com/fasterxml/jackson/module/kotlin Expand file tree Collapse file tree 2 files changed +47
-0
lines changed Original file line number Diff line number Diff line change 111
111
<artifactId >jackson-dataformat-xml</artifactId >
112
112
<scope >test</scope >
113
113
</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 >
114
121
</dependencies >
115
122
116
123
<build >
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments