SpyFactory

interface SpyFactory(source)

Creates a spy implementation for given type.

Unlike dev.mokkery.spy, which requires the spied type to be known at compile time, a factory creates spies from a KType resolved at runtime.

Use spyFactoryOf to create an instance of it.

Functions

Link copied to clipboard
abstract fun copy(newScope: MokkeryScope? = null, block: SpyFactoryConfigurer.Block = { }): SpyFactory

Copies this factory with applied block.

Link copied to clipboard
inline fun <T : Any> SpyFactory.create(obj: T, noinline block: MokkerySpyConfigurer.Block<T> = { }): T

Creates a spy of given type T wrapping obj or fails if T is not supported by this factory.

fun SpyFactory.create(type: KType, obj: Any, block: MokkerySpyConfigurer.Block<Any> = { }): Any

Creates a spy of given type wrapping obj or fails if type is not supported by this factory.

Link copied to clipboard
abstract fun createOrNull(type: KType, obj: Any, block: MokkerySpyConfigurer.Block<Any> = { }): Any?

Creates a spy of given type wrapping obj or null if type is not supported by this factory.

Link copied to clipboard
inline fun <T : Any> SpyFactory.createOrNull(obj: T, noinline block: MokkerySpyConfigurer.Block<T> = { }): T?

Creates a spy of given T wrapping obj and applies the block or returns null if T is not supported by this factory.

Link copied to clipboard
operator fun SpyFactory.plus(other: SpyFactory): SpyFactory

Returns a SpyFactory that combines this factory with other.