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 callSuspend with FunctionScope, 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 callSuspend to call with MokkerySuspendCallScope.
FunctionScope API mappings to MokkeryCallScope API:
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.
Calls block on call and callSuspend.
Just like Block but for suspending functions.
Returns value on call and callSuspend.
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.
Throws throwable on call and callSuspend
Functions
Provides a return value for a blocking function call with given scope.
Provides a return value for a suspend function call with given scope.
DEPRECATED: Use call with MokkeryBlockingCallScope instead!
DEPRECATED: Use call with MokkerySuspendCallScope instead!
Returns human-readable answer description. By default, it returns answers $this
. It's used for debugging purposes.