Package-level declarations

Types

Link copied to clipboard
interface Answer<out T>

An answer for a function call. For blocking answers only call implementation is required. For suspending answers callSuspend should be implemented and call implementation should throw an exception. Use Suspending for convenience.

Link copied to clipboard
interface AnsweringScope<T>

Scope for defining an answer for a function call.

Link copied to clipboard

Marker interface for defining an answer for non-suspend function call.

Link copied to clipboard

Provides a set of operation for BlockingAnsweringScope.calls.

Link copied to clipboard

Marker interface for sequential answer builder for non-suspend function

Link copied to clipboard
class CallArgs(val args: List<Any?>)

Contains arguments passed to mocked method. If method has extension receiver it is passed at the start of this list.

Link copied to clipboard
interface CallDefinitionScope<out R>

Provides a base set of operation for BlockingAnsweringScope.calls and SuspendAnsweringScope.calls.

Link copied to clipboard

Provides a set of mocked function related operations that might be required for implementing Answer.

Link copied to clipboard

Marker interface for sequential answer builder for any function

Link copied to clipboard
sealed interface SuperCall

Describes a super call that should be performed as an answer for a mocked method call.

Link copied to clipboard

Marker interface for defining an answer for suspend function call.

Link copied to clipboard

Provides a set of operation for SuspendAnsweringScope.calls.

Link copied to clipboard

Marker interface for sequential answer builder for suspend function

Functions

Link copied to clipboard
infix fun <T> AnsweringScope<T>.calls(superCall: SuperCall)

Calls super method according to SuperCall.

Function call executes block.

Suspend function call executes block.

Link copied to clipboard

Function call executes block inside runCatching and returns Result. It rethrows any dev.mokkery.MokkeryRuntimeException as it indicates internal error and cannot be ignored.

Suspend function call executes block inside runCatching and returns Result. It rethrows any dev.mokkery.MokkeryRuntimeException as it indicates internal error and cannot be ignored.

Link copied to clipboard

Allows to define a set of answers in sequentially that will repeat in cycles.

Link copied to clipboard
infix fun <T> AnsweringScope<T>.returns(value: T)

Function call always returns value.

Link copied to clipboard
infix fun <T> AnsweringScope<T>.returnsArgAt(index: Int)

Function call returns argument at index.

Link copied to clipboard
infix fun <T> AnsweringScope<T>.returnsBy(function: () -> T)

Function call returns value provided each time by function.

Link copied to clipboard
infix fun <T> AnsweringScope<in Result<T>>.returnsFailure(error: Throwable)

Function call returns Result.failure with error.

Link copied to clipboard
infix fun <T> AnsweringScope<in Result<T>>.returnsFailureBy(function: () -> Throwable)

Function call returns Result.failure with exception provided each time by function.

Link copied to clipboard
infix fun <T> AnsweringScope<in Result<T>>.returnsSuccess(value: T)

Function call returns Result.success with value.

Link copied to clipboard
infix fun <T> AnsweringScope<in Result<T>>.returnsSuccessBy(function: () -> T)

Function call returns Result.success with value provided each time by function.

Link copied to clipboard
inline fun <T> CallDefinitionScope<*>.self(): T
Link copied to clipboard

Function call will answer sequentially with answers defined in block.

Link copied to clipboard

Simplification for sequentially with multiple returns calls.

Link copied to clipboard

Simplification for sequentially with multiple throws calls.

Link copied to clipboard
infix fun <T> AnsweringScope<T>.throws(error: Throwable)

Function call always throws error.

Link copied to clipboard
infix fun <T> AnsweringScope<T>.throwsBy(function: () -> Throwable)

Function call throws exception provided each time by function.

Link copied to clipboard
infix fun <T> AnsweringScope<T>.throwsErrorWith(message: Any)

Function call always throws an IllegalStateException with given message.