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

Commit 8cfa689

Browse files
authored
Merge pull request #3 from k163377/feature
スコープ修正 + テスト追加 + Kotlinアップデート
2 parents 69c848f + 3001d28 commit 8cfa689

File tree

4 files changed

+45
-6
lines changed

4 files changed

+45
-6
lines changed

build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
plugins {
22
id("maven")
33
id("java")
4-
id("org.jetbrains.kotlin.jvm") version "1.3.61"
4+
id("org.jetbrains.kotlin.jvm") version "1.3.70"
55
id("org.jlleitschuh.gradle.ktlint") version "9.2.1"
66
}
77

@@ -18,7 +18,7 @@ buildscript {
1818
}
1919

2020
dependencies {
21-
classpath(kotlin("gradle-plugin", version = "1.3.61"))
21+
classpath(kotlin("gradle-plugin", version = "1.3.70"))
2222
}
2323
}
2424

src/main/kotlin/com/mapk/core/ArgumentBucket.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.mapk.core
22

3-
class ArgumentBucket(
4-
val bucket: Array<Any?>,
3+
class ArgumentBucket internal constructor(
4+
internal val bucket: Array<Any?>,
55
private var initializeStatus: Int,
66
private val initializeMask: List<Int>,
77
// clone時の再計算を避けるため1回で済むようにデフォルト値化

src/main/kotlin/com/mapk/core/KFunctionForCall.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ class KFunctionForCall<T>(private val function: KFunction<T>, instance: Any? = n
88
val parameters: List<KParameter> = function.parameters
99
private val originalArgumentBucket: ArgumentBucket
1010

11-
fun getArgumentBucket(): ArgumentBucket = originalArgumentBucket.clone()
12-
1311
init {
12+
if (parameters.isEmpty() || (instance != null && parameters.size == 1))
13+
throw IllegalArgumentException("This function is not require arguments.")
14+
1415
// この関数には確実にアクセスするためアクセシビリティ書き換え
1516
function.isAccessible = true
1617
originalArgumentBucket = if (instance != null) {
@@ -32,6 +33,8 @@ class KFunctionForCall<T>(private val function: KFunction<T>, instance: Any? = n
3233
}
3334
}
3435

36+
fun getArgumentBucket(): ArgumentBucket = originalArgumentBucket.clone()
37+
3538
fun call(argumentBucket: ArgumentBucket): T {
3639
return function.call(*argumentBucket.bucket)
3740
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.mapk.core
2+
3+
import org.junit.jupiter.api.DisplayName
4+
import org.junit.jupiter.api.Nested
5+
import org.junit.jupiter.api.Test
6+
import org.junit.jupiter.api.assertDoesNotThrow
7+
import org.junit.jupiter.api.assertThrows
8+
9+
class KFunctionForCallTest {
10+
@Nested
11+
@DisplayName("初期化関連テスト")
12+
inner class InitializeTest {
13+
// 空引数の関数
14+
private fun dummy1() {}
15+
@Suppress("UNUSED_PARAMETER")
16+
private fun dummy2(input: Int) {}
17+
18+
@Test
19+
@DisplayName("不正な関数を入力した場合")
20+
fun withNoInstance() {
21+
assertThrows<IllegalArgumentException> { KFunctionForCall(this::dummy1) }
22+
}
23+
24+
@Test
25+
@DisplayName("不正な関数を入力した場合(インスタンス付き = ファクトリーメソッド想定)")
26+
fun withInstance() {
27+
assertThrows<IllegalArgumentException> { KFunctionForCall(this::dummy2, object {}) }
28+
}
29+
30+
@Test
31+
@DisplayName("正常入力")
32+
fun isValid() {
33+
assertDoesNotThrow { KFunctionForCall(this::dummy2) }
34+
}
35+
}
36+
}

0 commit comments

Comments
 (0)