Answer

An answer for a function call.

Tips for providing correct implementation:

  • If you want to provide the same implementation for both blocking and suspending call, implement Answer.Unified instead.

  • If you want your answer to support only blocking or suspending calls, implement Answer.Blocking or Answer.Suspending.

  • Implement pure Answer if you want implement both methods separately.

  • Answers should not be used directly. It's a good practice to provide extension based API.

Check existing answers implementations for samples.

Migrations from FunctionScope to MokkeryCallScope:

FunctionScope API mappings to MokkeryCallScope API:

FunctionScope member functionMokkeryCallScope extensions
FunctionScope.returnTypeMokkeryCallScope.call ->dev.mokkery.context.FunctionCall.function ->dev.mokkery.context.Function.returnType
FunctionScope.argsMokkeryCallScope.call ->dev.mokkery.context.FunctionCall.argValues
FunctionScope.argMokkeryCallScope.call ->dev.mokkery.context.FunctionCall.argValue
FunctionScope.supersMokkeryCallScope.supers
FunctionScope.selfMokkeryCallScope.self
FunctionScope.callOriginalcallOriginal
FunctionScope.callSuspendOriginalcallOriginal
FunctionScope.callSupercallSuper
FunctionScope.callSuspendSupercallSuper

Inheritors

Types

Link copied to clipboard

Used whenever there is no defined answer for a call to mock that is in dev.mokkery.MockMode.autofill. Refer to AutofillProvider.forMockMode to read more about returned values.

Link copied to clipboard
Link copied to clipboard
interface Blocking<T> : Answer<T>

Convenience interface for blocking only answers. By default, it throws runtime exception on suspending call.

Link copied to clipboard

Just like Block but for suspending functions.

Link copied to clipboard
class Const<T>(val value: T) : Answer.Unified<T>

Returns value on call and callSuspend.

Link copied to clipboard
interface Sequential<T> : Answer<T>

Interface for every answer that have to be called in repeat when specified in sequentially.

Link copied to clipboard

Returns results of answers from iterator until empty. It supports nested Sequential answers and calls them until they are empty.

Link copied to clipboard
interface Suspending<T> : Answer<T>

Convenience interface for suspend only answers. By default, it throws runtime exception on blocking call.

Link copied to clipboard
class Throws(val throwable: Throwable) : Answer.Unified<Nothing>

Throws throwable on call and callSuspend

Link copied to clipboard
interface Unified<T> : Answer<T>

Convenience interface for answers with identical implementation for both blocking and suspending call.

Functions

Link copied to clipboard
open fun call(scope: MokkeryBlockingCallScope): T

Provides a return value for a blocking function call with given scope.

open suspend fun call(scope: MokkerySuspendCallScope): T

Provides a return value for a suspend function call with given scope.

open fun call(scope: FunctionScope): T

DEPRECATED: Use call with MokkeryBlockingCallScope instead!

Link copied to clipboard
open suspend fun callSuspend(scope: FunctionScope): T

DEPRECATED: Use call with MokkerySuspendCallScope instead!

Link copied to clipboard
open fun description(): String

Returns human-readable answer description. By default, it returns answers $this. It's used for debugging purposes.