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

Commit be5a212

Browse files
committed
コンパニオンオブジェクトを入れたときの呼び出し関連テストを追加
1 parent f197914 commit be5a212

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.mapk.core
22

3+
import kotlin.reflect.full.functions
4+
import org.junit.jupiter.api.Assertions.assertEquals
35
import org.junit.jupiter.api.DisplayName
46
import org.junit.jupiter.api.Nested
57
import org.junit.jupiter.api.Test
@@ -33,4 +35,28 @@ class KFunctionForCallTest {
3335
assertDoesNotThrow { KFunctionForCall(this::dummy2) }
3436
}
3537
}
38+
39+
@Nested
40+
@DisplayName("呼び出し関連テスト")
41+
inner class CallTest {
42+
@Test
43+
@DisplayName("コンパニオンオブジェクトから取得した場合")
44+
fun fromCompanionObject() {
45+
val function =
46+
Companion::class.functions.find { it.name == (KFunctionForCallTest)::declaredOnCompanionObject.name }!!
47+
48+
val kFunctionForCall = KFunctionForCall(function, Companion)
49+
50+
val bucket = kFunctionForCall.getArgumentBucket()
51+
kFunctionForCall.parameters.forEach { bucket.setArgument(it, it.index) }
52+
val result = kFunctionForCall.call(bucket)
53+
assertEquals("12", result)
54+
}
55+
}
56+
57+
companion object {
58+
fun declaredOnCompanionObject(arg1: Any, arg2: Any): String {
59+
return arg1.toString() + arg2.toString()
60+
}
61+
}
3662
}

0 commit comments

Comments
 (0)