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

Commit b786b9c

Browse files
committed
テスト修正
1 parent f4d3a6a commit b786b9c

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package com.mapk.core.internal
2+
3+
import org.junit.jupiter.api.Assertions.assertEquals
4+
import org.junit.jupiter.api.DisplayName
5+
import org.junit.jupiter.api.Nested
6+
import org.junit.jupiter.api.Test
7+
import kotlin.reflect.full.companionObject
8+
import kotlin.reflect.full.companionObjectInstance
9+
import kotlin.reflect.full.functions
10+
11+
@DisplayName("完全初期化時呼び出しのテスト")
12+
class FullInitializedFunctionWrapperTest {
13+
data class Dst(val foo: Int, val bar: String) {
14+
companion object {
15+
fun of(foo: Int, bar: String) = Dst(foo, bar)
16+
}
17+
}
18+
fun instanceMethod(foo: Int, bar: String) = Dst(foo, bar)
19+
private val expected = Dst(1, "2")
20+
21+
@Test
22+
@DisplayName("コンストラクタの場合")
23+
fun constructorTest() {
24+
val fullInitializedFunctionWrapper = FullInitializedFunctionWrapper(::Dst, null, 2)
25+
assertEquals(expected, fullInitializedFunctionWrapper.call(arrayOf(1, "2")))
26+
}
27+
28+
@Test
29+
@DisplayName("コンパニオンオブジェクトに定義した関数の場合")
30+
fun companionObjectFunTest() {
31+
val func = Dst::class.companionObject!!.functions.first { it.name == "of" }
32+
val instance = Dst::class.companionObjectInstance!!
33+
val fullInitializedFunctionWrapper = FullInitializedFunctionWrapper(
34+
func, instance, 3
35+
)
36+
assertEquals(expected, fullInitializedFunctionWrapper.call(arrayOf(instance, 1, "2")))
37+
}
38+
39+
@Nested
40+
@DisplayName("その他の場合")
41+
inner class OthersTest {
42+
@Test
43+
@DisplayName("コンパニオンオブジェクトに定義した関数をメソッドリファレンスで取得した場合")
44+
fun companionObjectFunByMethodReferenceTest() {
45+
val fullInitializedFunctionWrapper = FullInitializedFunctionWrapper((Dst)::of, null, 2)
46+
assertEquals(expected, fullInitializedFunctionWrapper.call(arrayOf(1, "2")))
47+
}
48+
49+
@Test
50+
@DisplayName("インスタンスメソッドの場合")
51+
fun instanceMethodTest() {
52+
val fullInitializedFunctionWrapper = FullInitializedFunctionWrapper(::instanceMethod, null, 2)
53+
assertEquals(expected, fullInitializedFunctionWrapper.call(arrayOf(1, "2")))
54+
}
55+
}
56+
}

0 commit comments

Comments
 (0)