From c447f459e81a41ce8952c668ee81ad9827c9a64a Mon Sep 17 00:00:00 2001 From: wrongwrong Date: Wed, 6 May 2020 17:35:23 +0900 Subject: [PATCH 01/19] =?UTF-8?q?=E3=83=95=E3=82=A9=E3=83=BC=E3=83=9E?= =?UTF-8?q?=E3=83=83=E3=83=88=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/com/mapk/core/internal/ArgumentBinder.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/kotlin/com/mapk/core/internal/ArgumentBinder.kt b/src/main/kotlin/com/mapk/core/internal/ArgumentBinder.kt index 1cc3b23..d10729d 100644 --- a/src/main/kotlin/com/mapk/core/internal/ArgumentBinder.kt +++ b/src/main/kotlin/com/mapk/core/internal/ArgumentBinder.kt @@ -22,8 +22,7 @@ internal sealed class ArgumentBinder(val annotations: List) { override val isOptional: Boolean, override val name: String, override val requiredClazz: KClass - ) : ArgumentBinder(annotations), - ValueParameter { + ) : ArgumentBinder(annotations), ValueParameter { override fun bindArgument(adaptor: ArgumentAdaptor, valueArray: Array): Boolean { return if (adaptor.isInitialized(name)) { valueArray[index] = adaptor.readout(name) From 48e12b2380f6fa374fb69b33677cd3352bffd9f7 Mon Sep 17 00:00:00 2001 From: wrongwrong Date: Wed, 6 May 2020 17:35:26 +0900 Subject: [PATCH 02/19] =?UTF-8?q?=E3=83=95=E3=82=A9=E3=83=BC=E3=83=9E?= =?UTF-8?q?=E3=83=83=E3=83=88=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/com/mapk/core/internal/ArgumentBucket.kt | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/com/mapk/core/internal/ArgumentBucket.kt b/src/main/kotlin/com/mapk/core/internal/ArgumentBucket.kt index 82f8457..fa7d1b1 100644 --- a/src/main/kotlin/com/mapk/core/internal/ArgumentBucket.kt +++ b/src/main/kotlin/com/mapk/core/internal/ArgumentBucket.kt @@ -17,8 +17,7 @@ internal class ArgumentBucket( override var value: Any? ) : Map.Entry - private val initializationStatusManager = - InitializationStatusManager(initializationStatus) + private val initializationStatusManager = InitializationStatusManager(initializationStatus) val isInitialized: Boolean override val size: Int @@ -32,9 +31,7 @@ internal class ArgumentBucket( size = initializationStatusManager.count } - override fun containsKey(key: KParameter): Boolean { - return initializationStatusManager.isInitialized(key.index) - } + override fun containsKey(key: KParameter): Boolean = initializationStatusManager.isInitialized(key.index) override fun containsValue(value: Any?): Boolean = valueArray.any { Objects.equals(value, it) } From 6bb3385328d2b3d23681f08dc565412dcb234969 Mon Sep 17 00:00:00 2001 From: wrongwrong Date: Wed, 6 May 2020 17:35:30 +0900 Subject: [PATCH 03/19] =?UTF-8?q?=E3=83=95=E3=82=A9=E3=83=BC=E3=83=9E?= =?UTF-8?q?=E3=83=83=E3=83=88=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/com/mapk/core/internal/BucketGenerator.kt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/kotlin/com/mapk/core/internal/BucketGenerator.kt b/src/main/kotlin/com/mapk/core/internal/BucketGenerator.kt index 2b87e1c..6766496 100644 --- a/src/main/kotlin/com/mapk/core/internal/BucketGenerator.kt +++ b/src/main/kotlin/com/mapk/core/internal/BucketGenerator.kt @@ -36,9 +36,7 @@ internal class BucketGenerator( } fun generate(adaptor: ArgumentAdaptor): ArgumentBucket = - ArgumentBucket( - parameters, originalValueArray.clone(), originalInitializationStatus.clone(), binders, adaptor - ) + ArgumentBucket(parameters, originalValueArray.clone(), originalInitializationStatus.clone(), binders, adaptor) } private fun KParameter.toArgumentBinder(parameterNameConverter: ParameterNameConverter): ArgumentBinder { From 41841a1cb547fefe4c10c0f2ab2fd98988fca40b Mon Sep 17 00:00:00 2001 From: wrongwrong Date: Wed, 6 May 2020 17:35:33 +0900 Subject: [PATCH 04/19] =?UTF-8?q?=E3=83=95=E3=82=A9=E3=83=BC=E3=83=9E?= =?UTF-8?q?=E3=83=83=E3=83=88=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/com/mapk/core/internal/Functions.kt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/kotlin/com/mapk/core/internal/Functions.kt b/src/main/kotlin/com/mapk/core/internal/Functions.kt index 89f160f..e362fc2 100644 --- a/src/main/kotlin/com/mapk/core/internal/Functions.kt +++ b/src/main/kotlin/com/mapk/core/internal/Functions.kt @@ -16,9 +16,7 @@ internal fun KParameter.getAliasOrName(): String? = findAnnotation Date: Wed, 6 May 2020 17:35:38 +0900 Subject: [PATCH 05/19] =?UTF-8?q?=E3=83=95=E3=82=A9=E3=83=BC=E3=83=9E?= =?UTF-8?q?=E3=83=83=E3=83=88=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/mapk/core/internal/ParameterNameConverter.kt | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/main/kotlin/com/mapk/core/internal/ParameterNameConverter.kt b/src/main/kotlin/com/mapk/core/internal/ParameterNameConverter.kt index f2ffeed..5cf6c8e 100644 --- a/src/main/kotlin/com/mapk/core/internal/ParameterNameConverter.kt +++ b/src/main/kotlin/com/mapk/core/internal/ParameterNameConverter.kt @@ -9,8 +9,7 @@ internal sealed class ParameterNameConverter { class Simple(override val converter: (String) -> String) : ParameterNameConverter() { override fun convert(name: String) = converter(name) - override fun nest(infix: String, nameJoiner: NameJoiner) = - WithPrefix(infix, nameJoiner, converter) + override fun nest(infix: String, nameJoiner: NameJoiner) = WithPrefix(infix, nameJoiner, converter) } class WithPrefix( @@ -22,11 +21,6 @@ internal sealed class ParameterNameConverter { // 結合を伴う変換では、「双方変換 -> 結合」の順で処理を行う override fun convert(name: String) = converter(name).let { nameJoiner.join(prefix, it) } - override fun nest(infix: String, nameJoiner: NameJoiner) = - WithPrefix( - convert(infix), - nameJoiner, - converter - ) + override fun nest(infix: String, nameJoiner: NameJoiner) = WithPrefix(convert(infix), nameJoiner, converter) } } From d78a0e22256ffb079905c105ec473ff105ff5174 Mon Sep 17 00:00:00 2001 From: wrongwrong Date: Wed, 6 May 2020 17:37:31 +0900 Subject: [PATCH 06/19] =?UTF-8?q?=E5=9B=BA=E6=9C=89=E5=90=8D=E3=81=AF?= =?UTF-8?q?=E5=9F=8B=E3=82=81=E8=BE=BC=E3=82=80=E5=BD=A2=E3=81=AB=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/com/mapk/core/internal/Functions.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/com/mapk/core/internal/Functions.kt b/src/main/kotlin/com/mapk/core/internal/Functions.kt index e362fc2..47bf781 100644 --- a/src/main/kotlin/com/mapk/core/internal/Functions.kt +++ b/src/main/kotlin/com/mapk/core/internal/Functions.kt @@ -5,6 +5,7 @@ import com.mapk.annotations.KUseDefaultArgument import java.lang.IllegalArgumentException import kotlin.reflect.KParameter import kotlin.reflect.full.findAnnotation +import kotlin.reflect.jvm.jvmName /** * パラメータからエイリアスもしくはプロパティ名を取得する関数 @@ -16,7 +17,9 @@ internal fun KParameter.getAliasOrName(): String? = findAnnotation Date: Wed, 6 May 2020 18:13:08 +0900 Subject: [PATCH 07/19] =?UTF-8?q?=E3=82=B7=E3=83=B3=E3=83=97=E3=83=AB?= =?UTF-8?q?=E5=A4=89=E6=8F=9B=E3=81=AE=E3=83=86=E3=82=B9=E3=83=88=E3=81=BE?= =?UTF-8?q?=E3=81=A7=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../internal/ParameterNameConverterTest.kt | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/test/kotlin/com/mapk/core/internal/ParameterNameConverterTest.kt diff --git a/src/test/kotlin/com/mapk/core/internal/ParameterNameConverterTest.kt b/src/test/kotlin/com/mapk/core/internal/ParameterNameConverterTest.kt new file mode 100644 index 0000000..8f36a4c --- /dev/null +++ b/src/test/kotlin/com/mapk/core/internal/ParameterNameConverterTest.kt @@ -0,0 +1,42 @@ +package com.mapk.core.internal + +import com.mapk.core.NameJoiner +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.DisplayName +import org.junit.jupiter.api.Nested +import org.junit.jupiter.api.Test + +@DisplayName("パラメータ名変換関連のテスト") +class ParameterNameConverterTest { + @Nested + @DisplayName("シンプルな変換機能のテスト") + inner class SimpleTest { + private val simple = ParameterNameConverter.Simple { it.toLowerCase() } + + @Test + @DisplayName("単純な変換テスト") + fun convertTest() { + val expected = "abcdef" + val actual = simple.convert("AbCdEf") + assertEquals(expected, actual) + } + + @Test + @DisplayName("ネストしたインスタンスを作るテスト") + fun nestTest() { + val nested1 = simple.nest("AbCdEf", NameJoiner.Kebab) + run { + val expected = "abcdef-ghijkl" + val actual = nested1.convert("gHiJkL") + assertEquals(expected, actual) + } + + val nested2 = nested1.nest("gHiJkL", NameJoiner.Snake) + run { + val expected = "abcdef-ghijkl_mnopqr" + val actual = nested2.convert("MNopQR") + assertEquals(expected, actual) + } + } + } +} From d3fd1217ac0ffc237a8713b1545db2e6d9209468 Mon Sep 17 00:00:00 2001 From: wrongwrong Date: Wed, 6 May 2020 18:21:00 +0900 Subject: [PATCH 08/19] =?UTF-8?q?=E3=83=97=E3=83=AC=E3=83=95=E3=82=A3?= =?UTF-8?q?=E3=83=83=E3=82=AF=E3=82=B9=E3=83=AA=E3=82=BB=E3=83=83=E3=83=88?= =?UTF-8?q?=E7=94=A8=E3=81=ABSimple=E3=81=B8=E3=81=AE=E5=A4=89=E6=8F=9B?= =?UTF-8?q?=E9=96=A2=E6=95=B0=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/com/mapk/core/internal/ParameterNameConverter.kt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/kotlin/com/mapk/core/internal/ParameterNameConverter.kt b/src/main/kotlin/com/mapk/core/internal/ParameterNameConverter.kt index 5cf6c8e..99fdb76 100644 --- a/src/main/kotlin/com/mapk/core/internal/ParameterNameConverter.kt +++ b/src/main/kotlin/com/mapk/core/internal/ParameterNameConverter.kt @@ -6,10 +6,12 @@ internal sealed class ParameterNameConverter { protected abstract val converter: (String) -> String abstract fun convert(name: String): String abstract fun nest(infix: String, nameJoiner: NameJoiner): WithPrefix + abstract fun toSimple(): Simple class Simple(override val converter: (String) -> String) : ParameterNameConverter() { override fun convert(name: String) = converter(name) override fun nest(infix: String, nameJoiner: NameJoiner) = WithPrefix(infix, nameJoiner, converter) + override fun toSimple(): Simple = this } class WithPrefix( @@ -22,5 +24,6 @@ internal sealed class ParameterNameConverter { // 結合を伴う変換では、「双方変換 -> 結合」の順で処理を行う override fun convert(name: String) = converter(name).let { nameJoiner.join(prefix, it) } override fun nest(infix: String, nameJoiner: NameJoiner) = WithPrefix(convert(infix), nameJoiner, converter) + override fun toSimple(): Simple = Simple(converter) } } From ffcff2d7cb31f02bf2aefca174082dbb5c5d3441 Mon Sep 17 00:00:00 2001 From: wrongwrong Date: Wed, 6 May 2020 18:21:22 +0900 Subject: [PATCH 09/19] =?UTF-8?q?=E3=83=97=E3=83=AC=E3=83=95=E3=82=A3?= =?UTF-8?q?=E3=83=83=E3=82=AF=E3=82=B9=E3=81=8C=E5=BF=85=E8=A6=81=E7=84=A1?= =?UTF-8?q?=E3=81=91=E3=82=8C=E3=81=B0Simple=E3=82=92=E4=BD=BF=E3=81=86?= =?UTF-8?q?=E3=82=88=E3=81=86=E3=81=AB=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/com/mapk/core/internal/BucketGenerator.kt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/com/mapk/core/internal/BucketGenerator.kt b/src/main/kotlin/com/mapk/core/internal/BucketGenerator.kt index 6766496..b73b2de 100644 --- a/src/main/kotlin/com/mapk/core/internal/BucketGenerator.kt +++ b/src/main/kotlin/com/mapk/core/internal/BucketGenerator.kt @@ -43,11 +43,13 @@ private fun KParameter.toArgumentBinder(parameterNameConverter: ParameterNameCon val name = getAliasOrName()!! return findAnnotation()?.let { annotation -> - // 名前の変換処理、結合が必要な場合はインスタンスを持ってきて対応する + // 名前の変換処理 val converter: ParameterNameConverter = if (annotation.fieldNameToPrefix) { + // 結合が必要な場合は結合機能のインスタンスを持ってきて対応する parameterNameConverter.nest(name, annotation.nameJoiner.objectInstance!!) } else { - parameterNameConverter + // プレフィックスを要求しない場合は全てsimpleでマップするように修正 + parameterNameConverter.toSimple() } ArgumentBinder.Function((type.classifier as KClass<*>).toKConstructor(converter), index, annotations) From b9eb46eef84366eca9a06076fcd75ae7fde66d74 Mon Sep 17 00:00:00 2001 From: wrongwrong Date: Wed, 6 May 2020 18:22:40 +0900 Subject: [PATCH 10/19] =?UTF-8?q?simple=E5=8C=96=E3=81=AE=E3=83=86?= =?UTF-8?q?=E3=82=B9=E3=83=88=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/mapk/core/internal/ParameterNameConverterTest.kt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/test/kotlin/com/mapk/core/internal/ParameterNameConverterTest.kt b/src/test/kotlin/com/mapk/core/internal/ParameterNameConverterTest.kt index 8f36a4c..7c59ccd 100644 --- a/src/test/kotlin/com/mapk/core/internal/ParameterNameConverterTest.kt +++ b/src/test/kotlin/com/mapk/core/internal/ParameterNameConverterTest.kt @@ -38,5 +38,12 @@ class ParameterNameConverterTest { assertEquals(expected, actual) } } + + @Test + @DisplayName("Simpleにした場合のテスト") + fun simple() { + val simple2 = simple.toSimple() + assertEquals(simple, simple2) + } } } From 3c0884d80ed5b082956e07e5264affa8a181d1b4 Mon Sep 17 00:00:00 2001 From: wrongwrong Date: Wed, 6 May 2020 18:40:08 +0900 Subject: [PATCH 11/19] =?UTF-8?q?=E3=83=97=E3=83=AC=E3=83=95=E3=82=A3?= =?UTF-8?q?=E3=83=83=E3=82=AF=E3=82=B9=E4=BB=98=E3=81=8D=E5=A4=89=E6=8F=9B?= =?UTF-8?q?=E6=A9=9F=E8=83=BD=E3=81=AE=E3=83=86=E3=82=B9=E3=83=88=E3=82=92?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../internal/ParameterNameConverterTest.kt | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/test/kotlin/com/mapk/core/internal/ParameterNameConverterTest.kt b/src/test/kotlin/com/mapk/core/internal/ParameterNameConverterTest.kt index 7c59ccd..66b8e91 100644 --- a/src/test/kotlin/com/mapk/core/internal/ParameterNameConverterTest.kt +++ b/src/test/kotlin/com/mapk/core/internal/ParameterNameConverterTest.kt @@ -46,4 +46,39 @@ class ParameterNameConverterTest { assertEquals(simple, simple2) } } + + @Nested + @DisplayName("プレフィックス付き変換機能のテスト") + inner class WithPrefixTest { + private val withPrefix = + ParameterNameConverter.WithPrefix("abcdef", NameJoiner.Snake) { it.toUpperCase() } + + @Test + @DisplayName("単純な変換テスト") + fun convertTest() { + val expected = "ABCDEF_GHIJKL" + val actual = withPrefix.convert("GhIJkL") + assertEquals(expected, actual) + } + + @Test + @DisplayName("ネストしたインスタンスを作るテスト") + fun nestTest() { + val nested = withPrefix.nest("GhIJkL", NameJoiner.Kebab) + run { + val expected = "ABCDEF_GHIJKL-MNOPQR" + val actual = nested.convert("mnOpQr") + assertEquals(expected, actual) + } + } + + @Test + @DisplayName("Simpleにした場合のテスト") + fun simple() { + val simple = withPrefix.toSimple() + val expected = "ABCDEF" + val actual = simple.convert(expected) + assertEquals(expected, actual) + } + } } From 4a1cff8201b6dbad563b2de87677d66e51cdd932 Mon Sep 17 00:00:00 2001 From: wrongwrong Date: Wed, 6 May 2020 19:27:12 +0900 Subject: [PATCH 12/19] =?UTF-8?q?=E3=83=97=E3=83=AC=E3=83=95=E3=82=A3?= =?UTF-8?q?=E3=83=83=E3=82=AF=E3=82=B9=E6=9C=89=E3=82=8A=20->=20=E7=84=A1?= =?UTF-8?q?=E3=81=97=E3=81=A7=E3=83=9E=E3=83=83=E3=83=97=E3=81=A7=E3=81=8D?= =?UTF-8?q?=E3=82=8B=E3=81=8B=E3=81=AE=E3=83=86=E3=82=B9=E3=83=88=E3=82=92?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/com/mapk/core/KParameterFlattenTest.kt | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/test/kotlin/com/mapk/core/KParameterFlattenTest.kt b/src/test/kotlin/com/mapk/core/KParameterFlattenTest.kt index 4de59a3..a3582a3 100644 --- a/src/test/kotlin/com/mapk/core/KParameterFlattenTest.kt +++ b/src/test/kotlin/com/mapk/core/KParameterFlattenTest.kt @@ -11,7 +11,8 @@ import org.junit.jupiter.api.Test @DisplayName("パラメータのフラット化テスト") class KParameterFlattenTest { - data class InnerDst1(val quxQux: Int) + data class InnerDst1(val quxQux: Int, @KParameterFlatten(fieldNameToPrefix = false) val fredFred: InnerInnerDst) + data class InnerInnerDst(val waldoWaldo: Int) data class InnerDst2(val quuxQuux: Int) data class InnerDst3(val graultGrault: String) { @KConstructor @@ -31,8 +32,14 @@ class KParameterFlattenTest { companion object { val expectedParams: Set = - linkedSetOf("fooFoo", "barBar", "bazBazQuxQux", "quuxQuux", "garplyGarply-graultGrault") - val expected: Dst = Dst(0, 1, InnerDst1(2), InnerDst2(3), InnerDst3("4")) + linkedSetOf("fooFoo", "barBar", "bazBazQuxQux", "waldoWaldo", "quuxQuux", "garplyGarply-graultGrault") + val expected: Dst = Dst( + 0, + 1, + InnerDst1(2, InnerInnerDst(3)), + InnerDst2(4), + InnerDst3("5") + ) } @Test From ef89d687d0bb5f0e49df8561e98dc38fe5b9eb39 Mon Sep 17 00:00:00 2001 From: wrongwrong Date: Sat, 9 May 2020 03:51:45 +0900 Subject: [PATCH 13/19] =?UTF-8?q?=E5=88=A4=E5=AE=9A=E3=83=9F=E3=82=B9?= =?UTF-8?q?=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/com/mapk/core/ArgumentAdaptor.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/com/mapk/core/ArgumentAdaptor.kt b/src/main/kotlin/com/mapk/core/ArgumentAdaptor.kt index 1887633..b011f1c 100644 --- a/src/main/kotlin/com/mapk/core/ArgumentAdaptor.kt +++ b/src/main/kotlin/com/mapk/core/ArgumentAdaptor.kt @@ -13,7 +13,7 @@ class ArgumentAdaptor(private val requiredParameters: Map Date: Sat, 9 May 2020 03:53:13 +0900 Subject: [PATCH 14/19] =?UTF-8?q?ArgumentAdaptor=E3=81=AE=E3=83=86?= =?UTF-8?q?=E3=82=B9=E3=83=88=E3=82=92null=E5=85=A5=E5=8A=9B=E5=91=A8?= =?UTF-8?q?=E3=82=8A=E3=81=BE=E3=81=A7=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/mapk/core/ArgumentAdaptorTest.kt | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/test/kotlin/com/mapk/core/ArgumentAdaptorTest.kt diff --git a/src/test/kotlin/com/mapk/core/ArgumentAdaptorTest.kt b/src/test/kotlin/com/mapk/core/ArgumentAdaptorTest.kt new file mode 100644 index 0000000..1e1ee3b --- /dev/null +++ b/src/test/kotlin/com/mapk/core/ArgumentAdaptorTest.kt @@ -0,0 +1,44 @@ +package com.mapk.core + +import io.mockk.every +import io.mockk.mockk +import org.junit.jupiter.api.Assertions.assertFalse +import org.junit.jupiter.api.Assertions.assertTrue +import org.junit.jupiter.api.DisplayName +import org.junit.jupiter.api.Nested +import org.junit.jupiter.api.Test + +@DisplayName("ArgumentAdaptorのテスト") +class ArgumentAdaptorTest { + private val keys = listOf("foo", "bar", "baz") + private val adaptor: ArgumentAdaptor = keys.mapIndexed { i, argName -> + mockk> { + every { name } returns argName + every { isNullable } returns (i % 2 == 0) + } + }.associateBy { + it.name + }.let { ArgumentAdaptor(it) } + + @Nested + @DisplayName("値をバインドするテスト") + inner class PutIfAbsentTest { + @Nested + @DisplayName("Null入力") + inner class NullabilityTest { + @Test + @DisplayName("nullableかつnull入力") + fun isNullableAndNull() { + adaptor.putIfAbsent(keys[0], null) + assertTrue(adaptor.isInitialized(keys[0])) + } + + @Test + @DisplayName("non-nullかつnull入力") + fun isNonNullAndNull() { + adaptor.putIfAbsent(keys[1], null) + assertFalse(adaptor.isInitialized(keys[0])) + } + } + } +} From 9727e2472dcaf255f89a07b1899bcda939af6240 Mon Sep 17 00:00:00 2001 From: wrongwrong Date: Sat, 9 May 2020 03:59:47 +0900 Subject: [PATCH 15/19] =?UTF-8?q?=E5=AE=8C=E5=85=A8=E5=88=9D=E6=9C=9F?= =?UTF-8?q?=E5=8C=96=E5=91=A8=E3=82=8A=E3=81=AE=E3=83=86=E3=82=B9=E3=83=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/mapk/core/ArgumentAdaptorTest.kt | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/test/kotlin/com/mapk/core/ArgumentAdaptorTest.kt b/src/test/kotlin/com/mapk/core/ArgumentAdaptorTest.kt index 1e1ee3b..7a3fefe 100644 --- a/src/test/kotlin/com/mapk/core/ArgumentAdaptorTest.kt +++ b/src/test/kotlin/com/mapk/core/ArgumentAdaptorTest.kt @@ -41,4 +41,23 @@ class ArgumentAdaptorTest { } } } + + @Nested + @DisplayName("完全初期化チェックのテスト") + inner class IsFullInitializedTest { + @Test + @DisplayName("完全初期化していない場合") + fun isNotFullInitialized() { + adaptor.putIfAbsent(keys[0], keys[0]) + adaptor.putIfAbsent(keys[1], keys[1]) + assertFalse(adaptor.isFullInitialized()) + } + + @Test + @DisplayName("完全初期化した場合") + fun isFullInitialized() { + keys.forEach { adaptor.putIfAbsent(it, it) } + assertTrue(adaptor.isFullInitialized()) + } + } } From 1d2ae00c3ead02a990a975a966349cd06450c6db Mon Sep 17 00:00:00 2001 From: wrongwrong Date: Sat, 9 May 2020 04:01:54 +0900 Subject: [PATCH 16/19] =?UTF-8?q?=E5=80=A4=E8=AA=AD=E3=81=BF=E5=87=BA?= =?UTF-8?q?=E3=81=97=E3=81=AE=E3=83=86=E3=82=B9=E3=83=88=E3=82=92=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/kotlin/com/mapk/core/ArgumentAdaptorTest.kt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/test/kotlin/com/mapk/core/ArgumentAdaptorTest.kt b/src/test/kotlin/com/mapk/core/ArgumentAdaptorTest.kt index 7a3fefe..b81f1c1 100644 --- a/src/test/kotlin/com/mapk/core/ArgumentAdaptorTest.kt +++ b/src/test/kotlin/com/mapk/core/ArgumentAdaptorTest.kt @@ -2,6 +2,7 @@ package com.mapk.core import io.mockk.every import io.mockk.mockk +import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertFalse import org.junit.jupiter.api.Assertions.assertTrue import org.junit.jupiter.api.DisplayName @@ -60,4 +61,11 @@ class ArgumentAdaptorTest { assertTrue(adaptor.isFullInitialized()) } } + + @Test + @DisplayName("読み出しテスト") + fun readoutTest() { + keys.forEach { adaptor.putIfAbsent(it, it) } + keys.forEach { assertEquals(it, adaptor.readout(it)) } + } } From ff6583eb38a0d226e53caba5acfc07e6fb1c2950 Mon Sep 17 00:00:00 2001 From: wrongwrong Date: Sat, 9 May 2020 04:07:23 +0900 Subject: [PATCH 17/19] =?UTF-8?q?=E5=AD=98=E5=9C=A8=E3=81=97=E3=81=AA?= =?UTF-8?q?=E3=81=84key=E3=81=AE=E8=AA=AD=E3=81=BF=E5=87=BA=E3=81=97?= =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/com/mapk/core/ArgumentAdaptorTest.kt | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/test/kotlin/com/mapk/core/ArgumentAdaptorTest.kt b/src/test/kotlin/com/mapk/core/ArgumentAdaptorTest.kt index b81f1c1..56039c0 100644 --- a/src/test/kotlin/com/mapk/core/ArgumentAdaptorTest.kt +++ b/src/test/kotlin/com/mapk/core/ArgumentAdaptorTest.kt @@ -8,6 +8,7 @@ import org.junit.jupiter.api.Assertions.assertTrue import org.junit.jupiter.api.DisplayName import org.junit.jupiter.api.Nested import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertThrows @DisplayName("ArgumentAdaptorのテスト") class ArgumentAdaptorTest { @@ -62,6 +63,22 @@ class ArgumentAdaptorTest { } } + @Nested + @DisplayName("存在しないkeyの読み出しテスト") + inner class NotContainsKeyTest { + @Test + @DisplayName("isInitializedのテスト") + fun isInitialized() { + assertThrows { adaptor.isInitialized("hoge") } + } + + @Test + @DisplayName("putIfAbsentのテスト") + fun putIfAbsent() { + assertThrows { adaptor.putIfAbsent("hoge", "hoge") } + } + } + @Test @DisplayName("読み出しテスト") fun readoutTest() { From 3acdd9976f02cc09526504f9014529cacdaac0c7 Mon Sep 17 00:00:00 2001 From: wrongwrong Date: Sat, 9 May 2020 04:09:08 +0900 Subject: [PATCH 18/19] =?UTF-8?q?2=E9=87=8D=E3=81=AB=E3=83=90=E3=82=A4?= =?UTF-8?q?=E3=83=B3=E3=83=89=E3=81=97=E3=81=9F=E5=A0=B4=E5=90=88=E3=81=AE?= =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/kotlin/com/mapk/core/ArgumentAdaptorTest.kt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/test/kotlin/com/mapk/core/ArgumentAdaptorTest.kt b/src/test/kotlin/com/mapk/core/ArgumentAdaptorTest.kt index 56039c0..f13c379 100644 --- a/src/test/kotlin/com/mapk/core/ArgumentAdaptorTest.kt +++ b/src/test/kotlin/com/mapk/core/ArgumentAdaptorTest.kt @@ -41,6 +41,14 @@ class ArgumentAdaptorTest { adaptor.putIfAbsent(keys[1], null) assertFalse(adaptor.isInitialized(keys[0])) } + + @Test + @DisplayName("2重バインドテスト") + fun isDuplicateKey() { + adaptor.putIfAbsent(keys[0], keys[0]) + adaptor.putIfAbsent(keys[0], keys[1]) + assertEquals(keys[0], adaptor.readout(keys[0])) + } } } From 10feb3b0a800c44f5f82b99e8ed9cd6d5eade299 Mon Sep 17 00:00:00 2001 From: wrongwrong Date: Sat, 9 May 2020 04:13:25 +0900 Subject: [PATCH 19/19] =?UTF-8?q?=E3=83=90=E3=83=BC=E3=82=B8=E3=83=A7?= =?UTF-8?q?=E3=83=B3=E3=82=A2=E3=83=83=E3=83=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index 5dfc6ac..97cba33 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -6,7 +6,7 @@ plugins { } group = "com.mapk" -version = "0.11" +version = "0.12" java { sourceCompatibility = JavaVersion.VERSION_1_8