Skip to content

Commit

Permalink
Use NoopCollector in MockFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
bitPogo committed Mar 26, 2022
1 parent 8e2e721 commit 15e80f6
Show file tree
Hide file tree
Showing 22 changed files with 86 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import tech.antibytes.kmock.processor.ProcessorContract
import tech.antibytes.kmock.processor.ProcessorContract.Companion.KMOCK_CONTRACT
import tech.antibytes.kmock.processor.ProcessorContract.Companion.KMOCK_FACTORY_TYPE_NAME
import tech.antibytes.kmock.processor.ProcessorContract.Companion.KSPY_FACTORY_TYPE_NAME
import tech.antibytes.kmock.processor.ProcessorContract.Companion.NOOP_COLLECTOR_NAME
import tech.antibytes.kmock.processor.ProcessorContract.TemplateSource

internal class KMockFactoryEntryPointGenerator(
Expand Down Expand Up @@ -128,6 +129,7 @@ internal class KMockFactoryEntryPointGenerator(

file.addAnnotation(unused)
file.addImport(KMOCK_CONTRACT.packageName, KMOCK_CONTRACT.simpleName)
file.addImport(NOOP_COLLECTOR_NAME.packageName, NOOP_COLLECTOR_NAME.simpleName)

file.addFunction(buildMockFactory())
file.addFunction(buildSpyFactory())
Expand Down Expand Up @@ -160,6 +162,7 @@ internal class KMockFactoryEntryPointGenerator(
file.addAnnotation(unused)

file.addImport(KMOCK_CONTRACT.packageName, KMOCK_CONTRACT.simpleName)
file.addImport(NOOP_COLLECTOR_NAME.packageName, NOOP_COLLECTOR_NAME.simpleName)

generateGenericEntryPoints(
file,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import tech.antibytes.kmock.processor.ProcessorContract
import tech.antibytes.kmock.processor.ProcessorContract.Companion.KMOCK_CONTRACT
import tech.antibytes.kmock.processor.ProcessorContract.Companion.KMOCK_FACTORY_TYPE_NAME
import tech.antibytes.kmock.processor.ProcessorContract.Companion.KSPY_FACTORY_TYPE_NAME
import tech.antibytes.kmock.processor.ProcessorContract.Companion.NOOP_COLLECTOR_NAME
import tech.antibytes.kmock.processor.ProcessorContract.Relaxer
import tech.antibytes.kmock.processor.ProcessorContract.TemplateSource

Expand Down Expand Up @@ -336,6 +337,10 @@ internal class KMockFactoryGenerator(
file.addAnnotation(unused)
file.addImport(KMOCK_CONTRACT.packageName, KMOCK_CONTRACT.simpleName)

if (!options.isKmp) {
file.addImport(NOOP_COLLECTOR_NAME.packageName, NOOP_COLLECTOR_NAME.simpleName)
}

val (regular, generics) = utils.splitInterfacesIntoRegularAndGenerics(templateSources)

val genericFactories = buildGenericFactories(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ internal class KMockFactoryGeneratorUtil(
): ParameterSpec {
val parameter = ParameterSpec.builder("verifier", ProcessorContract.COLLECTOR_NAME)
if (hasDefault) {
parameter.defaultValue("Collector { _, _ -> Unit }")
parameter.defaultValue("NoopCollector")
}

return parameter.build()
Expand Down Expand Up @@ -119,7 +119,6 @@ internal class KMockFactoryGeneratorUtil(

private fun buildSpyParameter(): ParameterSpec {
return ParameterSpec.builder("spyOn", TypeVariableName("SpyOn"))

.build()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ import kotlin.Boolean
import kotlin.Suppress
import tech.antibytes.kmock.KMockContract
import tech.antibytes.kmock.KMockContract.Collector
import tech.antibytes.kmock.proxy.NoopCollector

internal expect inline fun <reified Mock> kmock(
verifier: KMockContract.Collector = Collector { _, _ -> Unit },
verifier:KMockContract.Collector = NoopCollector,
relaxed: Boolean = false,
relaxUnitFun: Boolean = false,
freeze: Boolean = true
): Mock

internal expect inline fun <reified Mock : SpyOn, reified SpyOn> kspy(
spyOn: SpyOn,
verifier: KMockContract.Collector = Collector { _, _ -> Unit },
verifier:KMockContract.Collector = NoopCollector,
freeze: Boolean = true
): Mock
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import kotlin.Comparable
import kotlin.Suppress
import tech.antibytes.kmock.KMockContract
import tech.antibytes.kmock.KMockContract.Collector
import tech.antibytes.kmock.proxy.NoopCollector

internal inline fun <reified Mock> kmock(
verifier: KMockContract.Collector = Collector { _, _ -> Unit },
verifier:KMockContract.Collector = NoopCollector,
relaxed: Boolean = false,
relaxUnitFun: Boolean = false,
freeze: Boolean = true
Expand All @@ -21,14 +22,14 @@ internal inline fun <reified Mock> kmock(

internal inline fun <reified Mock : SpyOn, reified SpyOn> kspy(
spyOn: SpyOn,
verifier: KMockContract.Collector = Collector { _, _ -> Unit },
verifier:KMockContract.Collector = NoopCollector,
freeze: Boolean = true
): Mock = when (Mock::class) {
else -> throw RuntimeException("Unknown Interface ${Mock::class.simpleName}.")
}

internal inline fun <reified Mock : Generic<K, L>, K : Any, L> kmock(
verifier: KMockContract.Collector = Collector { _, _ -> Unit },
verifier:KMockContract.Collector = NoopCollector,
relaxed: Boolean = false,
relaxUnitFun: Boolean = false,
freeze: Boolean = true,
Expand All @@ -41,7 +42,7 @@ internal inline fun <reified Mock : Generic<K, L>, K : Any, L> kmock(

internal inline fun <reified Mock : SpyOn, reified SpyOn : Generic<K, L>, K : Any, L> kspy(
spyOn: SpyOn,
verifier: KMockContract.Collector = Collector { _, _ -> Unit },
verifier:KMockContract.Collector = NoopCollector,
freeze: Boolean = true,
templateType: kotlin.reflect.KClass<factory.template.alias.Generic<*, *>>
): Mock where L : Any, L : Comparable<L> = when (Mock::class) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import kotlin.Boolean
import kotlin.Suppress
import tech.antibytes.kmock.KMockContract
import tech.antibytes.kmock.KMockContract.Collector
import tech.antibytes.kmock.proxy.NoopCollector

internal inline fun <reified Mock> kmock(
verifier: KMockContract.Collector = Collector { _, _ -> Unit },
verifier:KMockContract.Collector = NoopCollector,
relaxed: Boolean = false,
relaxUnitFun: Boolean = false,
freeze: Boolean = true
Expand All @@ -21,7 +22,7 @@ internal inline fun <reified Mock> kmock(

internal inline fun <reified Mock : SpyOn, reified SpyOn> kspy(
spyOn: SpyOn,
verifier: KMockContract.Collector = Collector { _, _ -> Unit },
verifier:KMockContract.Collector = NoopCollector,
freeze: Boolean = true
): Mock = when (Mock::class) {
else -> throw RuntimeException("Unknown Interface ${Mock::class.simpleName}.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,23 @@ import kotlin.Comparable
import kotlin.Suppress
import tech.antibytes.kmock.KMockContract
import tech.antibytes.kmock.KMockContract.Collector
import tech.antibytes.kmock.proxy.NoopCollector

internal expect inline fun <reified Mock> kmock(
verifier: KMockContract.Collector = Collector { _, _ -> Unit },
verifier:KMockContract.Collector = NoopCollector,
relaxed: Boolean = false,
relaxUnitFun: Boolean = false,
freeze: Boolean = true
): Mock

internal expect inline fun <reified Mock : SpyOn, reified SpyOn> kspy(
spyOn: SpyOn,
verifier: KMockContract.Collector = Collector { _, _ -> Unit },
verifier:KMockContract.Collector = NoopCollector,
freeze: Boolean = true
): Mock

internal expect inline fun <reified Mock : Common<K, L>, K : Any, L> kmock(
verifier: KMockContract.Collector = Collector { _, _ -> Unit },
verifier:KMockContract.Collector = NoopCollector,
relaxed: Boolean = false,
relaxUnitFun: Boolean = false,
freeze: Boolean = true,
Expand All @@ -33,7 +34,7 @@ internal expect inline fun <reified Mock : Common<K, L>, K : Any, L> kmock(

internal expect inline fun <reified Mock : SpyOn, reified SpyOn : Common<K, L>, K : Any, L> kspy(
spyOn: SpyOn,
verifier: KMockContract.Collector = Collector { _, _ -> Unit },
verifier:KMockContract.Collector = NoopCollector,
freeze: Boolean = true,
templateType: kotlin.reflect.KClass<factory.template.generic.Common<*, *>>
): Mock where L : Any, L : Comparable<L>
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import kotlin.Comparable
import kotlin.Suppress
import tech.antibytes.kmock.KMockContract
import tech.antibytes.kmock.KMockContract.Collector
import tech.antibytes.kmock.proxy.NoopCollector

internal inline fun <reified Mock> kmock(
verifier: KMockContract.Collector = Collector { _, _ -> Unit },
verifier:KMockContract.Collector = NoopCollector,
relaxed: Boolean = false,
relaxUnitFun: Boolean = false,
freeze: Boolean = true
Expand All @@ -21,14 +22,14 @@ internal inline fun <reified Mock> kmock(

internal inline fun <reified Mock : SpyOn, reified SpyOn> kspy(
spyOn: SpyOn,
verifier: KMockContract.Collector = Collector { _, _ -> Unit },
verifier:KMockContract.Collector = NoopCollector,
freeze: Boolean = true
): Mock = when (Mock::class) {
else -> throw RuntimeException("Unknown Interface ${Mock::class.simpleName}.")
}

internal inline fun <reified Mock : Platform<K, L>, K : Any, L> kmock(
verifier: KMockContract.Collector = Collector { _, _ -> Unit },
verifier:KMockContract.Collector = NoopCollector,
relaxed: Boolean = false,
relaxUnitFun: Boolean = false,
freeze: Boolean = true,
Expand All @@ -41,7 +42,7 @@ internal inline fun <reified Mock : Platform<K, L>, K : Any, L> kmock(

internal inline fun <reified Mock : SpyOn, reified SpyOn : Platform<K, L>, K : Any, L> kspy(
spyOn: SpyOn,
verifier: KMockContract.Collector = Collector { _, _ -> Unit },
verifier:KMockContract.Collector = NoopCollector,
freeze: Boolean = true,
templateType: kotlin.reflect.KClass<factory.template.generic.Platform<*, *>>
): Mock where L : Any, L : Comparable<L> = when (Mock::class) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ import kotlin.Comparable
import kotlin.Suppress
import tech.antibytes.kmock.KMockContract
import tech.antibytes.kmock.KMockContract.Collector
import tech.antibytes.kmock.proxy.NoopCollector

internal expect inline fun <reified Mock : Shared1<K, L>, K : Any, L> kmock(
verifier: KMockContract.Collector = Collector { _, _ -> Unit },
verifier:KMockContract.Collector = NoopCollector,
relaxed: Boolean = false,
relaxUnitFun: Boolean = false,
freeze: Boolean = true,
Expand All @@ -21,13 +22,13 @@ internal expect inline fun <reified Mock : Shared1<K, L>, K : Any, L> kmock(

internal expect inline fun <reified Mock : SpyOn, reified SpyOn : Shared1<K, L>, K : Any, L> kspy(
spyOn: SpyOn,
verifier: KMockContract.Collector = Collector { _, _ -> Unit },
verifier:KMockContract.Collector = NoopCollector,
freeze: Boolean = true,
templateType: kotlin.reflect.KClass<factory.template.generic.Shared1<*, *>>
): Mock where L : Any, L : Comparable<L>

internal expect inline fun <reified Mock : Shared2<K, L>, K : Any, L> kmock(
verifier: KMockContract.Collector = Collector { _, _ -> Unit },
verifier:KMockContract.Collector = NoopCollector,
relaxed: Boolean = false,
relaxUnitFun: Boolean = false,
freeze: Boolean = true,
Expand All @@ -36,7 +37,7 @@ internal expect inline fun <reified Mock : Shared2<K, L>, K : Any, L> kmock(

internal expect inline fun <reified Mock : SpyOn, reified SpyOn : Shared2<K, L>, K : Any, L> kspy(
spyOn: SpyOn,
verifier: KMockContract.Collector = Collector { _, _ -> Unit },
verifier:KMockContract.Collector = NoopCollector,
freeze: Boolean = true,
templateType: kotlin.reflect.KClass<factory.template.generic.Shared2<*, *>>
): Mock where L : Any, L : Comparable<L>
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import kotlin.Comparable
import kotlin.Suppress
import tech.antibytes.kmock.KMockContract
import tech.antibytes.kmock.KMockContract.Collector
import tech.antibytes.kmock.proxy.NoopCollector

internal expect inline fun <reified Mock : Shared3<K, L>, K : Any, L> kmock(
verifier: KMockContract.Collector = Collector { _, _ -> Unit },
verifier:KMockContract.Collector = NoopCollector,
relaxed: Boolean = false,
relaxUnitFun: Boolean = false,
freeze: Boolean = true,
Expand All @@ -20,7 +21,7 @@ internal expect inline fun <reified Mock : Shared3<K, L>, K : Any, L> kmock(

internal expect inline fun <reified Mock : SpyOn, reified SpyOn : Shared3<K, L>, K : Any, L> kspy(
spyOn: SpyOn,
verifier: KMockContract.Collector = Collector { _, _ -> Unit },
verifier:KMockContract.Collector = NoopCollector,
freeze: Boolean = true,
templateType: kotlin.reflect.KClass<factory.template.generic.Shared3<*, *>>
): Mock where L : Any, L : Comparable<L>
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import kotlin.Comparable
import kotlin.Suppress
import tech.antibytes.kmock.KMockContract
import tech.antibytes.kmock.KMockContract.Collector
import tech.antibytes.kmock.proxy.NoopCollector

internal inline fun <reified Mock> kmock(
verifier: KMockContract.Collector = Collector { _, _ -> Unit },
verifier:KMockContract.Collector = NoopCollector,
relaxed: Boolean = false,
relaxUnitFun: Boolean = false,
freeze: Boolean = true
Expand All @@ -31,7 +32,7 @@ internal inline fun <reified Mock> kmock(

internal inline fun <reified Mock : SpyOn, reified SpyOn> kspy(
spyOn: SpyOn,
verifier: KMockContract.Collector = Collector { _, _ -> Unit },
verifier:KMockContract.Collector = NoopCollector,
freeze: Boolean = true
): Mock = when (Mock::class) {
factory.template.interfaze.Platform2::class -> factory.template.interfaze.Platform2Mock(verifier =
Expand All @@ -43,7 +44,7 @@ internal inline fun <reified Mock : SpyOn, reified SpyOn> kspy(
}

internal inline fun <reified Mock : Platform1<K, L>, K : Any, L> kmock(
verifier: KMockContract.Collector = Collector { _, _ -> Unit },
verifier:KMockContract.Collector = NoopCollector,
relaxed: Boolean = false,
relaxUnitFun: Boolean = false,
freeze: Boolean = true,
Expand All @@ -59,7 +60,7 @@ internal inline fun <reified Mock : Platform1<K, L>, K : Any, L> kmock(

internal inline fun <reified Mock : SpyOn, reified SpyOn : Platform1<K, L>, K : Any, L> kspy(
spyOn: SpyOn,
verifier: KMockContract.Collector = Collector { _, _ -> Unit },
verifier:KMockContract.Collector = NoopCollector,
freeze: Boolean = true,
templateType: kotlin.reflect.KClass<factory.template.interfaze.Platform1<*, *>>
): Mock where L : Any, L : Comparable<L> = when (Mock::class) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,23 @@ import kotlin.Comparable
import kotlin.Suppress
import tech.antibytes.kmock.KMockContract
import tech.antibytes.kmock.KMockContract.Collector
import tech.antibytes.kmock.proxy.NoopCollector

internal expect inline fun <reified Mock> kmock(
verifier: KMockContract.Collector = Collector { _, _ -> Unit },
verifier:KMockContract.Collector = NoopCollector,
relaxed: Boolean = false,
relaxUnitFun: Boolean = false,
freeze: Boolean = true
): Mock

internal expect inline fun <reified Mock : SpyOn, reified SpyOn> kspy(
spyOn: SpyOn,
verifier: KMockContract.Collector = Collector { _, _ -> Unit },
verifier:KMockContract.Collector = NoopCollector,
freeze: Boolean = true
): Mock

internal expect inline fun <reified Mock : Common1<K, L>, K : Any, L> kmock(
verifier: KMockContract.Collector = Collector { _, _ -> Unit },
verifier:KMockContract.Collector = NoopCollector,
relaxed: Boolean = false,
relaxUnitFun: Boolean = false,
freeze: Boolean = true,
Expand All @@ -33,7 +34,7 @@ internal expect inline fun <reified Mock : Common1<K, L>, K : Any, L> kmock(

internal expect inline fun <reified Mock : SpyOn, reified SpyOn : Common1<K, L>, K : Any, L> kspy(
spyOn: SpyOn,
verifier: KMockContract.Collector = Collector { _, _ -> Unit },
verifier:KMockContract.Collector = NoopCollector,
freeze: Boolean = true,
templateType: kotlin.reflect.KClass<factory.template.interfaze.Common1<*, *>>
): Mock where L : Any, L : Comparable<L>
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import kotlin.Comparable
import kotlin.Suppress
import tech.antibytes.kmock.KMockContract
import tech.antibytes.kmock.KMockContract.Collector
import tech.antibytes.kmock.proxy.NoopCollector

internal inline fun <reified Mock> kmock(
verifier: KMockContract.Collector = Collector { _, _ -> Unit },
verifier:KMockContract.Collector = NoopCollector,
relaxed: Boolean = false,
relaxUnitFun: Boolean = false,
freeze: Boolean = true
Expand All @@ -31,14 +32,14 @@ internal inline fun <reified Mock> kmock(

internal inline fun <reified Mock : SpyOn, reified SpyOn> kspy(
spyOn: SpyOn,
verifier: KMockContract.Collector = Collector { _, _ -> Unit },
verifier:KMockContract.Collector = NoopCollector,
freeze: Boolean = true
): Mock = when (Mock::class) {
else -> throw RuntimeException("Unknown Interface ${Mock::class.simpleName}.")
}

internal inline fun <reified Mock : Platform1<K, L>, K : Any, L> kmock(
verifier: KMockContract.Collector = Collector { _, _ -> Unit },
verifier:KMockContract.Collector = NoopCollector,
relaxed: Boolean = false,
relaxUnitFun: Boolean = false,
freeze: Boolean = true,
Expand All @@ -53,7 +54,7 @@ internal inline fun <reified Mock : Platform1<K, L>, K : Any, L> kmock(

internal inline fun <reified Mock : SpyOn, reified SpyOn : Platform1<K, L>, K : Any, L> kspy(
spyOn: SpyOn,
verifier: KMockContract.Collector = Collector { _, _ -> Unit },
verifier:KMockContract.Collector = NoopCollector,
freeze: Boolean = true,
templateType: kotlin.reflect.KClass<factory.template.interfaze.Platform1<*, *>>
): Mock where L : Any, L : Comparable<L> = when (Mock::class) {
Expand Down
Loading

0 comments on commit 15e80f6

Please sign in to comment.