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

io.justdevit.kotlin.boost.kotest.testcontainers.StubbingExtension.kt Maven / Gradle / Ivy

The newest version!
package io.justdevit.kotlin.boost.kotest.testcontainers

import io.justdevit.kotlin.boost.kotest.ExternalToolExtension
import io.kotest.core.spec.Spec
import io.kotest.core.spec.style.FreeSpec
import kotlin.reflect.KClass

/**
 * Represents a stubbing extension that conditionally stubs a specific class.
 *
 * @param predicate A function that determines whether the stubbing should occur or not.
 */
class StubbingExtension(private val predicate: () -> Boolean) : ExternalToolExtension {

    override fun  instantiate(clazz: KClass): Spec? {
        if (predicate()) {
            return object : FreeSpec(
                {
                    "STUB: ${clazz.simpleName}" {}
                },
            ) {}
        }
        return null
    }

    override fun mount(configure: Any.() -> Unit): Any = throw UnsupportedOperationException("Unable to mount: ${this.javaClass.simpleName}")
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy