Skip to content
This repository was archived by the owner on Jan 20, 2023. It is now read-only.

Commit f7406be

Browse files
committed
複数回呼んでもおかしな値を返さないかのテストを追加
1 parent 0459eae commit f7406be

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/test/kotlin/com/mapk/core/KFunctionForCallTest.kt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,28 @@ class KFunctionForCallTest {
7272
assertEquals("key" to "default", result)
7373
verify(exactly = 1) { func.callBy(any()) }
7474
}
75+
76+
@Test
77+
@DisplayName("同一関数を違うソースから複数回呼んだ場合")
78+
fun multipleCall() {
79+
val function = Companion::class.functions
80+
.first { it.name == (KFunctionForCallTest)::declaredOnCompanionObject.name }
81+
.let { spyk(it) }
82+
83+
val kFunctionForCall = KFunctionForCall(function, Companion)
84+
85+
val bucket1 = kFunctionForCall.getArgumentBucket()
86+
kFunctionForCall.parameters.forEach { bucket1.putIfAbsent(it, it.index) }
87+
val result1 = kFunctionForCall.call(bucket1)
88+
assertEquals("12", result1)
89+
90+
val bucket2 = kFunctionForCall.getArgumentBucket()
91+
kFunctionForCall.parameters.forEach { bucket2.putIfAbsent(it, it.index + 1) }
92+
val result2 = kFunctionForCall.call(bucket2)
93+
assertEquals("23", result2)
94+
95+
verify(exactly = 2) { function.call(*anyVararg()) }
96+
}
7597
}
7698

7799
companion object {

0 commit comments

Comments
 (0)