All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.io.mockk.impl.instantiation.AbstractInstantiator.kt Maven / Gradle / Ivy

There is a newer version: 1.13.12
Show newest version
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()
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy