diff --git a/build.gradle.kts b/build.gradle.kts index a26b7af..590f9f5 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -6,7 +6,7 @@ plugins { } group = "com.mapk" -version = "0.15" +version = "0.16" java { sourceCompatibility = JavaVersion.VERSION_1_8 @@ -30,7 +30,7 @@ repositories { dependencies { implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") implementation(kotlin("reflect")) - implementation("com.github.ProjectMapK:Shared:0.6") + api("com.github.ProjectMapK:Shared:0.7") // https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter testImplementation(group = "org.junit.jupiter", name = "junit-jupiter", version = "5.6.0") { diff --git a/src/main/kotlin/com/mapk/kmapper/KMapper.kt b/src/main/kotlin/com/mapk/kmapper/KMapper.kt index bf03103..e68ddc0 100644 --- a/src/main/kotlin/com/mapk/kmapper/KMapper.kt +++ b/src/main/kotlin/com/mapk/kmapper/KMapper.kt @@ -6,6 +6,7 @@ import com.mapk.core.ArgumentBucket import com.mapk.core.EnumMapper import com.mapk.core.KFunctionForCall import com.mapk.core.getAliasOrName +import com.mapk.core.isUseDefaultArgument import com.mapk.core.toKConstructor import java.lang.reflect.Method import kotlin.reflect.KClass @@ -29,7 +30,7 @@ class KMapper private constructor( ) private val parameterMap: Map> = function.parameters - .filter { it.kind != KParameter.Kind.INSTANCE } + .filter { it.kind != KParameter.Kind.INSTANCE && !it.isUseDefaultArgument() } .associate { (propertyNameConverter(it.getAliasOrName()!!)) to ParameterForMap.newInstance(it) } private fun bindArguments(argumentBucket: ArgumentBucket, src: Any) { diff --git a/src/test/kotlin/com/mapk/kmapper/DefaultArgumentTest.kt b/src/test/kotlin/com/mapk/kmapper/DefaultArgumentTest.kt new file mode 100644 index 0000000..c950702 --- /dev/null +++ b/src/test/kotlin/com/mapk/kmapper/DefaultArgumentTest.kt @@ -0,0 +1,20 @@ +package com.mapk.kmapper + +import com.mapk.annotations.KUseDefaultArgument +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.DisplayName +import org.junit.jupiter.api.Test + +@DisplayName("デフォルト引数を指定するテスト") +class DefaultArgumentTest { + data class Dst(val fooArgument: Int, @param:KUseDefaultArgument val barArgument: String = "default") + data class Src(val fooArgument: Int, val barArgument: String) + + @Test + fun test() { + val src = Src(1, "src") + + val result = KMapper(::Dst).map(src) + assertEquals(Dst(1, "default"), result) + } +}