MockFactory

interface MockFactory(source)

Creates a mock implementation for given type.

Unlike dev.mokkery.mock, which requires the mocked type to be known at compile time, a factory creates mocks from a KType resolved at runtime.

Use mockFactoryOf to create an instance of it.

Functions

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

Copies a factory with given configuration block applied.

Link copied to clipboard
inline fun <T : Any> MockFactory.create(noinline block: MokkeryMockConfigurer.Block<T> = { }): T

Creates a mock of given T and applies the block or fails if T is not supported by this factory.

Creates a mock of given type and applies the block or fails if type is not supported by this factory.

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

Creates a mock of given type or null if type is not supported by this factory.

Link copied to clipboard
inline fun <T : Any> MockFactory.createOrNull(noinline block: MokkeryMockConfigurer.Block<T> = { }): T?

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

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

Returns a MockFactory that combines this factory with other.