Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ import org.koin.test.parameter.MockParameter
/**
* Check all definition's dependencies - start all modules and check if definitions can run
*/
@Deprecated(
message = "Migrate to verify() API",
replaceWith = ReplaceWith("org.koin.test.verify.Verify")
)
fun KoinApplication.checkModules(parameters: CheckParameters? = null) = koin.checkModules(parameters)

/**
Expand All @@ -53,10 +49,6 @@ fun KoinApplication.checkModules(parameters: CheckParameters? = null) = koin.che
* @param parameters - parameter setup
* @param appDeclaration - koin Application
*/
@Deprecated(
message = "Migrate to verify() API",
replaceWith = ReplaceWith("org.koin.test.verify.Verify")
)
fun checkModules(level: Level = Level.INFO, parameters: CheckParameters? = null, appDeclaration: KoinAppDeclaration) {
startKoin(appDeclaration)
.logger(KoinPlatformTools.defaultLogger(level))
Expand All @@ -70,10 +62,6 @@ fun checkModules(level: Level = Level.INFO, parameters: CheckParameters? = null,
* @param appDeclaration - Koin app config if needed
* @param parameters - Check parameters DSL
*/
@Deprecated(
message = "Migrate to verify() API",
replaceWith = ReplaceWith("modules.verifyAll()", "org.koin.test.verify.verifyAll")
)
fun checkKoinModules(modules: List<Module>, appDeclaration: KoinAppDeclaration = {}, parameters: CheckParameters? = null) {
startKoin(appDeclaration)
.modules(modules)
Expand Down Expand Up @@ -110,10 +98,6 @@ fun checkKoinModules(vararg modules: Module, level: Level = Level.INFO, paramete
/**
* Check all definition's dependencies - start all modules and check if definitions can run
*/
@Deprecated(
message = "Migrate to verify() API",
replaceWith = ReplaceWith("org.koin.test.verify.Verify")
)
fun Koin.checkModules(parametersDefinition: CheckParameters? = null) {
logger.info("[Check] checking modules ...")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@ import kotlin.reflect.KClass

//TODO TO BE DEPRECATED in 4.0

@Deprecated("Migrate to verify() API")
data class CheckedComponent(val qualifier: Qualifier? = null, val type: KClass<*>)

@Deprecated("Migrate to verify() API")
class ParametersBinding(val koin: Koin) {

val parametersCreators = mutableMapOf<CheckedComponent, ParametersCreator>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,20 @@ class Simple {
class MyComplexBool(val a : ComponentA, val b : Boolean)

fun buildB(a: ComponentA) : MyComponentB = ComponentB(a)

class ComponentProvider {
fun getComponent(): ComponentToBeProvided {
return ComponentToBeProvided()
}

fun getComponentWithArg(a: ComponentA): ComponentToBeProvidedWithComponentA {
return ComponentToBeProvidedWithComponentA(a = a)
}
}

class ComponentToBeProvided

class ComponentToBeProvidedWithComponentA(val a: ComponentA)
}

object UpperCase : Qualifier {
Expand Down
79 changes: 79 additions & 0 deletions projects/core/koin-test/src/jvmTest/kotlin/VerifyModulesTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import org.koin.dsl.module
import org.koin.test.Simple
import org.koin.test.verify.*

/**
* @author Arnauld Giuliani
* @author Otávio Moreira
* */
class VerifyModulesTest {

@Test
Expand Down Expand Up @@ -262,4 +266,79 @@ class VerifyModulesTest {
e.printStackTrace()
}
}

@Test
fun `verify instance provided by other definition`() {
val modules = module {
single { Simple.ComponentProvider() }
single<Simple.ComponentToBeProvided> {
get<Simple.ComponentProvider>().getComponent()
}
}

modules.verify()
}

@Test
fun `verify instance provided by other definition - fail`() {
val modules = module {
single<Simple.ComponentToBeProvided> {
get<Simple.ComponentProvider>().getComponent()
}
}

try {
modules.verify()
fail()
} catch (e: Exception) {
e.printStackTrace()
}
}

@Test
fun `verify instance provided by other definition passing arg`() {
val modules = module {
single { Simple.ComponentA() }
single { Simple.ComponentProvider() }
single<Simple.ComponentToBeProvidedWithComponentA> {
get<Simple.ComponentProvider>().getComponentWithArg(a = get())
}
}

modules.verify()
}

@Test
fun `verify instance provided by other definition passing arg - fail without provider`() {
val modules = module {
single { Simple.ComponentA() }
single<Simple.ComponentToBeProvidedWithComponentA> {
get<Simple.ComponentProvider>().getComponentWithArg(a = get())
}
}

try {
modules.verify()
fail()
} catch (e: Exception) {
e.printStackTrace()
}
}

@Test
fun `verify instance provided by other definition passing arg - fail without arg`() {
val modules = module {
single { Simple.ComponentProvider() }
single<Simple.ComponentToBeProvidedWithComponentA> {
get<Simple.ComponentProvider>().getComponentWithArg(a = get())
}
}

try {
modules.verify()
fail()
} catch (e: Exception) {
e.printStackTrace()
}
}
}