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

Commit 4d2aa24

Browse files
committed
non-null要求関連のテストを追加
1 parent b3798a4 commit 4d2aa24

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

src/test/kotlin/com/mapk/core/ArgumentBucketTest.kt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,28 @@
11
package com.mapk.core
22

3+
import com.mapk.annotations.KParameterRequireNonNull
34
import org.junit.jupiter.api.Assertions.assertEquals
45
import org.junit.jupiter.api.Assertions.assertFalse
6+
import org.junit.jupiter.api.Assertions.assertNull
57
import org.junit.jupiter.api.Assertions.assertTrue
68
import org.junit.jupiter.api.BeforeEach
79
import org.junit.jupiter.api.DisplayName
810
import org.junit.jupiter.api.Nested
911
import org.junit.jupiter.api.Test
12+
import org.junit.jupiter.api.assertDoesNotThrow
13+
import org.junit.jupiter.api.assertThrows
1014

1115
private fun sampleFunction(arg1: Any?, arg2: Any?, arg3: Any?) {
1216
println(arg1)
1317
println(arg2)
1418
println(arg3)
1519
}
1620

21+
private fun sampleAnnotatedFunction(@KParameterRequireNonNull arg1: Any, arg2: Any?) {
22+
println(arg1)
23+
println(arg2)
24+
}
25+
1726
@DisplayName("ArgumentBucketTestのテスト")
1827
class ArgumentBucketTest {
1928
@Nested
@@ -68,4 +77,29 @@ class ArgumentBucketTest {
6877
}
6978
}
7079
}
80+
81+
@Nested
82+
@DisplayName("アノテーションを付与した場合のテスト")
83+
inner class AnnotatedParametersTest {
84+
@Test
85+
@DisplayName("non-null要求のテスト")
86+
fun isRequireNonNull() {
87+
val forCall = KFunctionForCall(::sampleAnnotatedFunction)
88+
val argumentBucket = forCall.getArgumentBucket()
89+
val parameters = forCall.parameters
90+
91+
argumentBucket.putIfAbsent(parameters[0], null)
92+
assertThrows<IllegalStateException> { argumentBucket.getByIndex(0) }
93+
94+
argumentBucket.putIfAbsent(parameters[0], "input")
95+
assertDoesNotThrow {
96+
assertEquals("input", argumentBucket.getByIndex(0))
97+
}
98+
99+
argumentBucket.putIfAbsent(parameters[1], null)
100+
assertDoesNotThrow {
101+
assertNull(argumentBucket.getByIndex(1))
102+
}
103+
}
104+
}
71105
}

0 commit comments

Comments
 (0)