@@ -135,4 +135,74 @@ private class SingleArgFastKFunctionTest {
135
135
assertTrue(result is SingleArgFastKFunction .TopLevelFunction )
136
136
}
137
137
}
138
+
139
+ @Nested
140
+ inner class InstanceFunctionOfTest {
141
+ fun instanceFunc (arg : String ) = println (arg)
142
+
143
+ @Nested
144
+ inner class KindIsInstance {
145
+ val function: KFunction <Unit > = InstanceFunctionOfTest ::instanceFunc
146
+ val parameters = function.parameters
147
+ val javaMethod = function.javaMethod!!
148
+
149
+ @Test
150
+ fun withoutInstance () {
151
+ assertThrows<IllegalArgumentException > {
152
+ SingleArgFastKFunction .instanceFunctionOf(function, null , parameters, javaMethod)
153
+ }
154
+ }
155
+
156
+ @Test
157
+ fun withWrongInstance () {
158
+ assertThrows<IllegalArgumentException > {
159
+ SingleArgFastKFunction .instanceFunctionOf(function, " " , parameters, javaMethod)
160
+ }
161
+ }
162
+
163
+ @Test
164
+ fun isCorrect () {
165
+ val result = assertDoesNotThrow {
166
+ SingleArgFastKFunction .instanceFunctionOf(
167
+ function, this @InstanceFunctionOfTest, parameters, javaMethod
168
+ )
169
+ }
170
+ assertTrue(result is SingleArgFastKFunction .InstanceFunction )
171
+ }
172
+ }
173
+
174
+ @Nested
175
+ inner class InstanceFunction {
176
+ val function: KFunction <Unit > = this @InstanceFunctionOfTest::instanceFunc
177
+ val parameters = function.parameters
178
+ val javaMethod = function.javaMethod!!
179
+
180
+ @Test
181
+ fun withoutInstance () {
182
+ val result = assertDoesNotThrow {
183
+ SingleArgFastKFunction .instanceFunctionOf(
184
+ function, null , parameters, javaMethod
185
+ )
186
+ }
187
+ assertTrue(result is SingleArgFastKFunction .Function )
188
+ }
189
+
190
+ @Test
191
+ fun withWrongInstance () {
192
+ assertThrows<IllegalArgumentException > {
193
+ SingleArgFastKFunction .instanceFunctionOf(function, " " , parameters, javaMethod)
194
+ }
195
+ }
196
+
197
+ @Test
198
+ fun withCorrectInstance () {
199
+ val result = assertDoesNotThrow {
200
+ SingleArgFastKFunction .instanceFunctionOf(
201
+ function, this @InstanceFunctionOfTest, parameters, javaMethod
202
+ )
203
+ }
204
+ assertTrue(result is SingleArgFastKFunction .InstanceFunction )
205
+ }
206
+ }
207
+ }
138
208
}
0 commit comments