diff --git a/examples/src/commonTest/kotlin/tech/antibytes/kmock/example/MockFactory.kt b/examples/src/commonTest/kotlin/tech/antibytes/kmock/example/MockFactory.kt index 6636a2a4..5d6f8e1d 100644 --- a/examples/src/commonTest/kotlin/tech/antibytes/kmock/example/MockFactory.kt +++ b/examples/src/commonTest/kotlin/tech/antibytes/kmock/example/MockFactory.kt @@ -11,6 +11,7 @@ import tech.antibytes.kmock.KMockContract internal expect inline fun kmock( verifier: KMockContract.Collector = KMockContract.Collector { _, _ -> Unit }, relaxed: Boolean = false, + relaxUnitFun: Boolean = false, freeze: Boolean = true ): T diff --git a/kmock-gradle/src/main/kotlin/tech/antibytes/gradle/kmock/FactoryGenerator.kt b/kmock-gradle/src/main/kotlin/tech/antibytes/gradle/kmock/FactoryGenerator.kt index 05782329..43c90934 100644 --- a/kmock-gradle/src/main/kotlin/tech/antibytes/gradle/kmock/FactoryGenerator.kt +++ b/kmock-gradle/src/main/kotlin/tech/antibytes/gradle/kmock/FactoryGenerator.kt @@ -30,6 +30,12 @@ internal object FactoryGenerator : KMockPluginContract.FactoryGenerator { .build() } + private fun buildUnitRelaxedParameter(): ParameterSpec { + return ParameterSpec.builder("relaxUnitFun", Boolean::class) + .defaultValue("false") + .build() + } + private fun buildVerifierParameter(): ParameterSpec { return ParameterSpec.builder("verifier", COLLECTOR_NAME) .defaultValue("Collector { _, _ -> Unit }") @@ -51,6 +57,7 @@ internal object FactoryGenerator : KMockPluginContract.FactoryGenerator { .returns(type) .addParameter(buildVerifierParameter()) .addParameter(buildRelaxedParameter()) + .addParameter(buildUnitRelaxedParameter()) .addParameter(buildFreezeParameter()) .addModifiers(KModifier.EXPECT) .build() diff --git a/kmock-gradle/src/test/kotlin/tech/antibytes/gradle/kmock/FactoryGeneratorSpec.kt b/kmock-gradle/src/test/kotlin/tech/antibytes/gradle/kmock/FactoryGeneratorSpec.kt index b8f2a48c..7b14a030 100644 --- a/kmock-gradle/src/test/kotlin/tech/antibytes/gradle/kmock/FactoryGeneratorSpec.kt +++ b/kmock-gradle/src/test/kotlin/tech/antibytes/gradle/kmock/FactoryGeneratorSpec.kt @@ -62,6 +62,8 @@ class FactoryGeneratorSpec { } } + println(actual) + actual!!.normalizeSource() mustBe expected.normalizeSource() } } diff --git a/kmock-gradle/src/test/resources/generatorTest/MockFactory.kt b/kmock-gradle/src/test/resources/generatorTest/MockFactory.kt index 8e3fe16d..12c8ce1c 100644 --- a/kmock-gradle/src/test/resources/generatorTest/MockFactory.kt +++ b/kmock-gradle/src/test/resources/generatorTest/MockFactory.kt @@ -8,6 +8,7 @@ import tech.antibytes.kmock.KMockContract.Collector internal expect inline fun kmock( verifier: KMockContract.Collector = Collector { _, _ -> Unit }, relaxed: Boolean = false, + relaxUnitFun: Boolean = false, freeze: Boolean = true ): T diff --git a/kmock-processor/src/main/kotlin/tech/antibytes/kmock/processor/KMockFactoryGenerator.kt b/kmock-processor/src/main/kotlin/tech/antibytes/kmock/processor/KMockFactoryGenerator.kt index ea44937a..86dcd68e 100644 --- a/kmock-processor/src/main/kotlin/tech/antibytes/kmock/processor/KMockFactoryGenerator.kt +++ b/kmock-processor/src/main/kotlin/tech/antibytes/kmock/processor/KMockFactoryGenerator.kt @@ -34,6 +34,17 @@ internal class KMockFactoryGenerator( return parameter.build() } + private fun buildUnitRelaxedParameter( + isKmp: Boolean + ): ParameterSpec { + val parameter = ParameterSpec.builder("relaxUnitFun", Boolean::class) + if (!isKmp) { + parameter.defaultValue("false") + } + + return parameter.build() + } + private fun buildVerifierParameter( isKmp: Boolean ): ParameterSpec { @@ -67,24 +78,24 @@ internal class KMockFactoryGenerator( if (relaxer == null) { function.addStatement( - "%L::class -> %LMock(verifier = verifier, freeze = freeze) as T", + "%L::class -> %LMock(verifier = verifier, relaxUnitFun = relaxUnitFun, freeze = freeze) as T", qualifiedName, interfaceName, ) function.addStatement( - "%LMock::class -> %LMock(verifier = verifier, freeze = freeze) as T", + "%LMock::class -> %LMock(verifier = verifier, relaxUnitFun = relaxUnitFun, freeze = freeze) as T", interfaceName, interfaceName, ) } else { function.addStatement( - "%L::class -> %LMock(verifier = verifier, relaxed = relaxed, freeze = freeze) as T", + "%L::class -> %LMock(verifier = verifier, relaxed = relaxed, relaxUnitFun = relaxUnitFun, freeze = freeze) as T", qualifiedName, interfaceName, ) function.addStatement( - "%LMock::class -> %LMock(verifier = verifier, relaxed = relaxed, freeze = freeze) as T", + "%LMock::class -> %LMock(verifier = verifier, relaxed = relaxed, relaxUnitFun = relaxUnitFun, freeze = freeze) as T", interfaceName, interfaceName, ) @@ -109,6 +120,7 @@ internal class KMockFactoryGenerator( .returns(type) .addParameter(buildVerifierParameter(isKmp)) .addParameter(buildRelaxedParameter(isKmp)) + .addParameter(buildUnitRelaxedParameter(isKmp)) .addParameter(buildFreezeParameter(isKmp)) if (isKmp) { diff --git a/kmock-processor/src/test/resources/generatorTest/FactoryCommonExpected.kt b/kmock-processor/src/test/resources/generatorTest/FactoryCommonExpected.kt index f6d8461c..3158a0a4 100644 --- a/kmock-processor/src/test/resources/generatorTest/FactoryCommonExpected.kt +++ b/kmock-processor/src/test/resources/generatorTest/FactoryCommonExpected.kt @@ -7,12 +7,13 @@ import tech.antibytes.kmock.KMockContract.Collector internal actual inline fun kmock( verifier: KMockContract.Collector, relaxed: Boolean, + relaxUnitFun: Boolean, freeze: Boolean ): T = when (T::class) { generatorTest.PropertyCommon::class -> generatorTest.PropertyCommonMock(verifier = verifier, - freeze = freeze) as T + relaxUnitFun = relaxUnitFun, freeze = freeze) as T generatorTest.PropertyCommonMock::class -> generatorTest.PropertyCommonMock(verifier = verifier, - freeze = freeze) as T + relaxUnitFun = relaxUnitFun, freeze = freeze) as T else -> throw RuntimeException("Unknown Interface ${T::class.simpleName}.") } diff --git a/kmock-processor/src/test/resources/generatorTest/FactoryPlatformExpected.kt b/kmock-processor/src/test/resources/generatorTest/FactoryPlatformExpected.kt index 50fcf34d..8fa052b1 100644 --- a/kmock-processor/src/test/resources/generatorTest/FactoryPlatformExpected.kt +++ b/kmock-processor/src/test/resources/generatorTest/FactoryPlatformExpected.kt @@ -7,12 +7,13 @@ import tech.antibytes.kmock.KMockContract.Collector internal inline fun kmock( verifier: KMockContract.Collector = Collector { _, _ -> Unit }, relaxed: Boolean = false, + relaxUnitFun: Boolean = false, freeze: Boolean = true ): T = when (T::class) { generatorTest.PropertyPlatform::class -> generatorTest.PropertyPlatformMock(verifier = verifier, - freeze = freeze) as T + relaxUnitFun = relaxUnitFun, freeze = freeze) as T generatorTest.PropertyPlatformMock::class -> generatorTest.PropertyPlatformMock(verifier = - verifier, freeze = freeze) as T + verifier, relaxUnitFun = relaxUnitFun, freeze = freeze) as T else -> throw RuntimeException("Unknown Interface ${T::class.simpleName}.") } diff --git a/kmock-processor/src/test/resources/generatorTest/FactoryRelaxedExpected.kt b/kmock-processor/src/test/resources/generatorTest/FactoryRelaxedExpected.kt index 7412f66c..466a6588 100644 --- a/kmock-processor/src/test/resources/generatorTest/FactoryRelaxedExpected.kt +++ b/kmock-processor/src/test/resources/generatorTest/FactoryRelaxedExpected.kt @@ -7,12 +7,13 @@ import tech.antibytes.kmock.KMockContract.Collector internal inline fun kmock( verifier: KMockContract.Collector = Collector { _, _ -> Unit }, relaxed: Boolean = false, + relaxUnitFun: Boolean = false, freeze: Boolean = true ): T = when (T::class) { generatorTest.Relaxed::class -> generatorTest.RelaxedMock(verifier = verifier, relaxed = relaxed, - freeze = freeze) as T + relaxUnitFun = relaxUnitFun, freeze = freeze) as T generatorTest.RelaxedMock::class -> generatorTest.RelaxedMock(verifier = verifier, relaxed = - relaxed, freeze = freeze) as T + relaxed, relaxUnitFun = relaxUnitFun, freeze = freeze) as T else -> throw RuntimeException("Unknown Interface ${T::class.simpleName}.") }