io.justdevit.kotlin.boost.kotest.testcontainers.StubbingExtension.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of boost-kotest-testcontainers Show documentation
Show all versions of boost-kotest-testcontainers Show documentation
Library to boost working with Kotlin/JVM projects.
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