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

Commit 5465444

Browse files
committed
変なreceiverを渡した時のテストを追加
1 parent 7980f05 commit 5465444

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

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

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,18 +79,25 @@ private class SingleArgFastKFunctionTest {
7979
@Nested
8080
inner class TopLevelFunctionOfTest {
8181
@Nested
82+
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
8283
inner class KindIsExtensionFunction {
8384
val function: KFunction<Unit> = String::topLevelExtensionFunc
8485
val parameters = function.parameters
8586
val javaMethod = function.javaMethod!!
8687

87-
@Test
88-
fun nullInstanceTest() {
88+
@ParameterizedTest
89+
@MethodSource("illegalReceiverProvider")
90+
fun illegalReceiverTest(receiver: Any?) {
8991
assertThrows<IllegalArgumentException> {
90-
SingleArgFastKFunction.topLevelFunctionOf(function, null, parameters, javaMethod)
92+
SingleArgFastKFunction.topLevelFunctionOf(function, receiver, parameters, javaMethod)
9193
}
9294
}
9395

96+
fun illegalReceiverProvider(): Stream<Arguments> = Stream.of(
97+
Arguments.of(null),
98+
Arguments.of(0)
99+
)
100+
94101
@Test
95102
fun isCorrect() {
96103
val result = assertDoesNotThrow {
@@ -107,6 +114,13 @@ private class SingleArgFastKFunctionTest {
107114
val parameters = function.parameters
108115
val javaMethod = function.javaMethod!!
109116

117+
@Test
118+
fun withIllegalReceiverTest() {
119+
assertThrows<IllegalArgumentException> {
120+
SingleArgFastKFunction.topLevelFunctionOf(function, 0, parameters, javaMethod)
121+
}
122+
}
123+
110124
@Test
111125
fun withInstanceTest() {
112126
val result = assertDoesNotThrow {

0 commit comments

Comments
 (0)