commonMain.org.koin.test.mock.MockProvider.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of koin-test-jvm Show documentation
Show all versions of koin-test-jvm Show documentation
KOIN - Kotlin simple Dependency Injection Framework
The newest version!
package org.koin.test.mock
import kotlin.reflect.KClass
object MockProvider {
private var _provider: Provider<*>? = null
val provider: Provider<*>
get() {
return _provider
?: error("Missing MockProvider. Please use MockProvider.register() to register a new mock provider")
}
fun register(provider: Provider<*>) {
_provider = provider
}
inline fun makeMock(): T {
return provider.invoke(T::class) as T
}
@Suppress("UNCHECKED_CAST")
fun makeMock(kClass: KClass): T {
return provider.invoke(kClass) as T
}
}
typealias Provider = (KClass) -> T