Answer
An answer for a function call.
call with MokkeryBlockingCallScope is invoked on blocking function call.
call with MokkerySuspendCallScope is invoked on suspending 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:
If your answer overrides both call and
callSuspendwithFunctionScope, migrate to call with MokkeryBlockingCallScope and call with MokkerySuspendCallScope.If your answer overrides only call with
FunctionScope, it means that it was possible to call this answer in both blocking and suspending context. In this case you need to change the base type from Answer to Answer.Unified. Now, override call with MokkeryCallScope.If your answer overrides Answer.Suspending simply migrate from
callSuspendto call with MokkerySuspendCallScope.
FunctionScope API mappings to MokkeryCallScope API:
FunctionScope member function | MokkeryCallScope extensions |
|---|---|
FunctionScope.returnType] | MokkeryCallScope.call ->dev.mokkery.context.FunctionCall.function ->dev.mokkery.context.Function.returnType |
FunctionScope.args | MokkeryCallScope.call ->dev.mokkery.context.FunctionCall.argValues |
FunctionScope.arg | MokkeryCallScope.call ->dev.mokkery.context.FunctionCall.argValue |
FunctionScope.supers | MokkeryCallScope.supers |
FunctionScope.self | MokkeryCallScope.self |
FunctionScope.callOriginal | callOriginal |
FunctionScope.callSuspendOriginal | callOriginal |
FunctionScope.callSuper | callSuper |
FunctionScope.callSuspendSuper | callSuper |
Inheritors
Types
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.
Just like Block but for suspending functions.
Interface for every answer that have to be called in repeat when specified in sequentially.
Returns results of answers from iterator until empty. It supports nested Sequential answers and calls them until they are empty.
Convenience interface for suspend only answers. By default, it throws runtime exception on blocking call.
Functions
Returns human-readable answer description. By default, it returns answers $this. It's used for debugging purposes.