From 44ce659ad16e7a84e006ee6e20cd9697abecfbf4 Mon Sep 17 00:00:00 2001 From: Arnaud Giuliani Date: Mon, 16 Sep 2024 10:44:14 +0200 Subject: [PATCH] adjust verify fix message --- .../kotlin/org/koin/test/verify/Verification.kt | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/projects/core/koin-test/src/jvmMain/kotlin/org/koin/test/verify/Verification.kt b/projects/core/koin-test/src/jvmMain/kotlin/org/koin/test/verify/Verification.kt index 53af6e6a3..5d71b7cc3 100644 --- a/projects/core/koin-test/src/jvmMain/kotlin/org/koin/test/verify/Verification.kt +++ b/projects/core/koin-test/src/jvmMain/kotlin/org/koin/test/verify/Verification.kt @@ -62,7 +62,7 @@ class Verification(val module: Module, extraTypes: List>, injections: verificationByStatus[VerificationStatus.MISSING]?.let { list -> val first = list.first() val errorMessage = "Missing definition for '$first' in definition '$beanDefinition'." - val generateParameterInjection = "Fix your Koin configuration or define it as injection for '$beanDefinition':\n${generateInjectionCode(beanDefinition,first)}" + val generateParameterInjection = "- Fix your Koin configuration -\n${generateFixDefinition(first)}\n${generateInjectionCode(beanDefinition,first)}" System.err.println("* ----- > $errorMessage\n$generateParameterInjection") throw MissingKoinDefinitionException(errorMessage) } @@ -78,11 +78,21 @@ class Verification(val module: Module, extraTypes: List>, injections: } ?: emptyList() } + private fun generateFixDefinition(first: VerifiedParameter): String { + val className = first.type.qualifiedName + return """ + 1- add missing definition for type '$className'. like: singleOf(::$className) + or + """.trimIndent() + } + private fun generateInjectionCode(beanDefinition: BeanDefinition<*>, p: VerifiedParameter): String { + val className = beanDefinition.primaryType.qualifiedName return """ + 2- else define injection for '$className' with: module.verify( injections = injectedParameters( - definition<${beanDefinition.primaryType.qualifiedName}>(${p.type.qualifiedName}::class) + definition<$className>(${p.type.qualifiedName}::class) ) ) """.trimIndent()