|
1 | 1 | package com.mapk.core |
2 | 2 |
|
| 3 | +import com.mapk.annotations.KParameterRequireNonNull |
3 | 4 | import org.junit.jupiter.api.Assertions.assertEquals |
4 | 5 | import org.junit.jupiter.api.Assertions.assertFalse |
| 6 | +import org.junit.jupiter.api.Assertions.assertNull |
5 | 7 | import org.junit.jupiter.api.Assertions.assertTrue |
6 | 8 | import org.junit.jupiter.api.BeforeEach |
7 | 9 | import org.junit.jupiter.api.DisplayName |
8 | 10 | import org.junit.jupiter.api.Nested |
9 | 11 | import org.junit.jupiter.api.Test |
| 12 | +import org.junit.jupiter.api.assertDoesNotThrow |
| 13 | +import org.junit.jupiter.api.assertThrows |
10 | 14 |
|
11 | 15 | private fun sampleFunction(arg1: Any?, arg2: Any?, arg3: Any?) { |
12 | 16 | println(arg1) |
13 | 17 | println(arg2) |
14 | 18 | println(arg3) |
15 | 19 | } |
16 | 20 |
|
| 21 | +private fun sampleAnnotatedFunction(@KParameterRequireNonNull arg1: Any, arg2: Any?) { |
| 22 | + println(arg1) |
| 23 | + println(arg2) |
| 24 | +} |
| 25 | + |
17 | 26 | @DisplayName("ArgumentBucketTestのテスト") |
18 | 27 | class ArgumentBucketTest { |
19 | 28 | @Nested |
@@ -68,4 +77,29 @@ class ArgumentBucketTest { |
68 | 77 | } |
69 | 78 | } |
70 | 79 | } |
| 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 | + } |
71 | 105 | } |
0 commit comments