|
| 1 | +package com.mapk.core |
| 2 | + |
| 3 | +import org.junit.jupiter.api.Assertions.assertEquals |
| 4 | +import org.junit.jupiter.api.Assertions.assertFalse |
| 5 | +import org.junit.jupiter.api.Assertions.assertIterableEquals |
| 6 | +import org.junit.jupiter.api.Assertions.assertTrue |
| 7 | +import org.junit.jupiter.api.BeforeEach |
| 8 | +import org.junit.jupiter.api.DisplayName |
| 9 | +import org.junit.jupiter.api.Nested |
| 10 | +import org.junit.jupiter.api.Test |
| 11 | + |
| 12 | +private fun sampleFunction(arg1: Any?, arg2: Any?, arg3: Any?) { |
| 13 | + println(arg1) |
| 14 | + println(arg2) |
| 15 | + println(arg3) |
| 16 | +} |
| 17 | + |
| 18 | +@DisplayName("ArgumentBucketTestのテスト") |
| 19 | +class ArgumentBucketTest { |
| 20 | + private lateinit var argumentBucket: ArgumentBucket |
| 21 | + |
| 22 | + @BeforeEach |
| 23 | + fun beforeEach() { |
| 24 | + argumentBucket = KFunctionForCall(::sampleFunction).getArgumentBucket() |
| 25 | + } |
| 26 | + |
| 27 | + @Nested |
| 28 | + @DisplayName("初期化状態のチェックテスト") |
| 29 | + inner class IsInitializedTest { |
| 30 | + @Test |
| 31 | + @DisplayName("初期化前") |
| 32 | + fun isNotInitialized() { |
| 33 | + assertFalse(argumentBucket.isInitialized) |
| 34 | + } |
| 35 | + |
| 36 | + @Test |
| 37 | + @DisplayName("初期化後") |
| 38 | + fun isInitialized() { |
| 39 | + argumentBucket.setArgument(object {}, 0) |
| 40 | + argumentBucket.setArgument(object {}, 1) |
| 41 | + argumentBucket.setArgument(object {}, 2) |
| 42 | + assertTrue(argumentBucket.isInitialized) |
| 43 | + } |
| 44 | + } |
| 45 | + |
| 46 | + @Nested |
| 47 | + @DisplayName("初期化されていないインデックス取得のテスト") |
| 48 | + inner class NotInitializedParameterIndexesTest { |
| 49 | + @Test |
| 50 | + @DisplayName("何もセットしていない場合") |
| 51 | + fun noArguments() { |
| 52 | + assertIterableEquals(listOf(0, 1, 2), argumentBucket.notInitializedParameterIndexes) |
| 53 | + } |
| 54 | + |
| 55 | + @Test |
| 56 | + @DisplayName("1つセットした場合") |
| 57 | + fun singleArgument() { |
| 58 | + argumentBucket.setArgument(object {}, 1) |
| 59 | + assertIterableEquals(listOf(0, 2), argumentBucket.notInitializedParameterIndexes) |
| 60 | + } |
| 61 | + |
| 62 | + @Test |
| 63 | + @DisplayName("全てセットした場合") |
| 64 | + fun fullArguments() { |
| 65 | + argumentBucket.setArgument(object {}, 0) |
| 66 | + argumentBucket.setArgument(object {}, 1) |
| 67 | + argumentBucket.setArgument(object {}, 2) |
| 68 | + assertIterableEquals(emptyList<Any?>(), argumentBucket.notInitializedParameterIndexes) |
| 69 | + } |
| 70 | + } |
| 71 | + |
| 72 | + @Nested |
| 73 | + @DisplayName("引数セットのテスト") |
| 74 | + inner class SetArgumentTest { |
| 75 | + @Test |
| 76 | + @DisplayName("正常に追加した場合") |
| 77 | + fun setNewArgument() { |
| 78 | + argumentBucket.setArgument("argument", 0) |
| 79 | + assertEquals("argument", argumentBucket.bucket[0]) |
| 80 | + } |
| 81 | + |
| 82 | + @Test |
| 83 | + @DisplayName("同じインデックスに2回追加した場合") |
| 84 | + fun setArgumentTwice() { |
| 85 | + argumentBucket.setArgument("first", 0) |
| 86 | + argumentBucket.setArgument("second", 0) |
| 87 | + assertEquals("first", argumentBucket.bucket[0]) |
| 88 | + } |
| 89 | + } |
| 90 | +} |
0 commit comments