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

Commit b9403a9

Browse files
committed
topLevelFunctionOfのテストを追加
1 parent 59e5366 commit b9403a9

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

src/test/kotlin/com/mapk/fastkfunction/SingleArgFastKFunctionTest.kt

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import com.mapk.fastkfunction.SingleArgFastKFunction.Companion.checkParameters
44
import io.mockk.every
55
import io.mockk.mockk
66
import org.junit.jupiter.api.Assertions.assertEquals
7+
import org.junit.jupiter.api.Assertions.assertTrue
78
import org.junit.jupiter.api.Nested
89
import org.junit.jupiter.api.Test
910
import org.junit.jupiter.api.TestInstance
@@ -13,7 +14,12 @@ import org.junit.jupiter.params.ParameterizedTest
1314
import org.junit.jupiter.params.provider.Arguments
1415
import org.junit.jupiter.params.provider.MethodSource
1516
import java.util.stream.Stream
17+
import kotlin.reflect.KFunction
1618
import kotlin.reflect.KParameter
19+
import kotlin.reflect.jvm.javaMethod
20+
21+
private fun topLevelFunc(arg: String) = println(arg)
22+
private fun String.topLevelExtensionFunc(arg: String) = println(this + arg)
1723

1824
private class SingleArgFastKFunctionTest {
1925
@Nested
@@ -69,4 +75,64 @@ private class SingleArgFastKFunctionTest {
6975
Arguments.of(listOf(instanceParameter, valueParameter))
7076
)
7177
}
78+
79+
@Nested
80+
inner class TopLevelFunctionOfTest {
81+
@Nested
82+
inner class KindIsExtensionFunction {
83+
val function: KFunction<Unit> = String::topLevelExtensionFunc
84+
val parameters = function.parameters
85+
val javaMethod = function.javaMethod!!
86+
87+
@Test
88+
fun nullInstanceTest() {
89+
assertThrows<IllegalArgumentException> {
90+
SingleArgFastKFunction.topLevelFunctionOf(function, null, parameters, javaMethod)
91+
}
92+
}
93+
94+
@Test
95+
fun isCorrect() {
96+
val result = assertDoesNotThrow {
97+
SingleArgFastKFunction.topLevelFunctionOf(function, "", parameters, javaMethod)
98+
}
99+
assertTrue(result is SingleArgFastKFunction.TopLevelExtensionFunction)
100+
}
101+
}
102+
103+
@Nested
104+
inner class ExtensionFunction {
105+
val instance = ""
106+
val function: KFunction<Unit> = instance::topLevelExtensionFunc
107+
val parameters = function.parameters
108+
val javaMethod = function.javaMethod!!
109+
110+
@Test
111+
fun withInstanceTest() {
112+
val result = assertDoesNotThrow {
113+
SingleArgFastKFunction.topLevelFunctionOf(function, "", parameters, javaMethod)
114+
}
115+
assertTrue(result is SingleArgFastKFunction.TopLevelExtensionFunction)
116+
}
117+
118+
@Test
119+
fun withoutInstanceTest() {
120+
val result = assertDoesNotThrow {
121+
SingleArgFastKFunction.topLevelFunctionOf(function, null, parameters, javaMethod)
122+
}
123+
assertTrue(result is SingleArgFastKFunction.Function)
124+
}
125+
}
126+
127+
@Test
128+
fun topLevelFunctionTest() {
129+
val function: KFunction<Unit> = ::topLevelFunc
130+
val parameters = function.parameters
131+
132+
val result = assertDoesNotThrow {
133+
SingleArgFastKFunction.topLevelFunctionOf(function, null, parameters, function.javaMethod!!)
134+
}
135+
assertTrue(result is SingleArgFastKFunction.TopLevelFunction)
136+
}
137+
}
72138
}

0 commit comments

Comments
 (0)