@@ -5,11 +5,17 @@ import io.mockk.every
5
5
import io.mockk.mockk
6
6
import org.junit.jupiter.api.*
7
7
import org.junit.jupiter.api.Assertions.assertEquals
8
+ import org.junit.jupiter.api.Assertions.assertTrue
8
9
import org.junit.jupiter.params.ParameterizedTest
9
10
import org.junit.jupiter.params.provider.Arguments
10
11
import org.junit.jupiter.params.provider.MethodSource
11
12
import java.util.stream.Stream
13
+ import kotlin.reflect.KFunction
12
14
import kotlin.reflect.KParameter
15
+ import kotlin.reflect.jvm.javaMethod
16
+
17
+ private fun topLevelFunc (arg : String ) = println (arg)
18
+ private fun String.topLevelExtensionFunc (arg : String ) = println (this + arg)
13
19
14
20
private class FastKFunctionTest {
15
21
val valueParameter = mockk<KParameter >() {
@@ -55,4 +61,64 @@ private class FastKFunctionTest {
55
61
Arguments .of(listOf (instanceParameter, valueParameter))
56
62
)
57
63
}
64
+
65
+ @Nested
66
+ inner class TopLevelFunctionOfTest {
67
+ @Nested
68
+ inner class KindIsExtensionFunction {
69
+ val function: KFunction <Unit > = String ::topLevelExtensionFunc
70
+ val parameters = function.parameters
71
+ val javaMethod = function.javaMethod!!
72
+
73
+ @Test
74
+ fun nullInstanceTest () {
75
+ assertThrows<IllegalArgumentException > {
76
+ FastKFunction .topLevelFunctionOf(function, null , parameters, javaMethod)
77
+ }
78
+ }
79
+
80
+ @Test
81
+ fun isCorrect () {
82
+ val result = assertDoesNotThrow {
83
+ FastKFunction .topLevelFunctionOf(function, " " , parameters, javaMethod)
84
+ }
85
+ assertTrue(result is FastKFunction .TopLevelExtensionFunction )
86
+ }
87
+ }
88
+
89
+ @Nested
90
+ inner class ExtensionFunction {
91
+ val instance = " "
92
+ val function: KFunction <Unit > = instance::topLevelExtensionFunc
93
+ val parameters = function.parameters
94
+ val javaMethod = function.javaMethod!!
95
+
96
+ @Test
97
+ fun withInstanceTest () {
98
+ val result = assertDoesNotThrow {
99
+ FastKFunction .topLevelFunctionOf(function, " " , parameters, javaMethod)
100
+ }
101
+ assertTrue(result is FastKFunction .TopLevelExtensionFunction )
102
+ }
103
+
104
+ @Test
105
+ fun withoutInstanceTest () {
106
+ val result = assertDoesNotThrow {
107
+ FastKFunction .topLevelFunctionOf(function, null , parameters, javaMethod)
108
+ }
109
+ assertTrue(result is FastKFunction .Function )
110
+ }
111
+ }
112
+
113
+ @Test
114
+ fun topLevelFunctionTest () {
115
+ val function: KFunction <Unit > = ::topLevelFunc
116
+ val parameters = function.parameters
117
+
118
+ val result = assertDoesNotThrow {
119
+ FastKFunction .topLevelFunctionOf(function, null , parameters, function.javaMethod!! )
120
+ }
121
+ assertTrue(result is FastKFunction .TopLevelFunction )
122
+ }
123
+ }
58
124
}
0 commit comments