wheneverBlocking

fun <T> wheneverBlocking(methodCall: suspend CoroutineScope.() -> T): OngoingStubbing<T>

Deprecated

Use whenever { mock.methodCall() } instead

Enables stubbing methods/function calls. In case of Kotlin function calls, these can be either synchronous or suspendable function calls.

This is a deprecated alias for whenever. Please use whenever instead.

Return

OngoingStubbing object used to stub fluently. Do not create a reference to this returned object.

Parameters

methodCall

(regular or suspendable) lambda, wrapping the function call to be stubbed.


fun <T> Stubber.wheneverBlocking(mock: T, methodCall: suspend T.() -> Unit)

Deprecated

Use whenever(mock) { methodCall() } instead

Sets the mock and the method call to be stubbed. With this version of whenever you can reverse stub either synchronous or suspendable function calls.

Reverse stubbing is especially useful when stubbing a void method (or Unit function) to throw an exception.

Warning: Only one method call can be stubbed in the function. Subsequent method calls are ignored!

Example:

    doThrow(RuntimeException()).wheneverBlocking(mock) { someMethod() }

This function is an alias for whenever.

Parameters

mock

the mock to stub the method/function call on.

methodCall

(regular or suspendable) lambda, wrapping the method/function call to be stubbed.