commonMain.io.mockk.impl.instantiation.AbstractInstantiator.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mockk-jvm Show documentation
Show all versions of mockk-jvm Show documentation
Mocking library for Kotlin
package io.mockk.impl.instantiation
import io.mockk.impl.log.Logger
import kotlin.reflect.KClass
abstract class AbstractInstantiator(val instanceFactoryRegistry: CommonInstanceFactoryRegistry) {
@Suppress("UNCHECKED_CAST")
fun instantiateViaInstanceFactoryRegistry(cls: KClass, orInstantiate: () -> T): T {
for (factory in instanceFactoryRegistry.instanceFactories) {
val instance = factory.instantiate(cls)
if (instance != null) {
log.trace { "Instance factory returned instance $instance" }
return instance as T
}
}
return orInstantiate()
}
abstract fun instantiate(cls: KClass): T
companion object {
val log = Logger()
}
}