on
Enables stubbing methods/function calls. In case of Kotlin function calls, these can be either synchronous or suspendable function calls.
Simply put: "on a call to the x function then return y".
Examples:
stubbing(mock) {
on(mock.someFunction()) doReturn 10
}This function is an alias for Mockito.when. So, for more detailed documentation, please refer to the Javadoc of that method in the Mockito class. For stubbing Unit functions (or Java void methods) with throwables, see: Mockito.doThrow.
Return
OngoingStubbing object used to stub fluently. Do not create a reference to this returned object.
Parameters
method call to be stubbed.
Enables stubbing methods/function calls. In case of Kotlin function calls, these can be either synchronous or suspendable function calls.
Simply put: "on a call to the x function then return y".
Examples:
stubbing(mock) {
on { mock.someFunction() } doReturn 10
}This function is an alias for Mockito.when. So, for more detailed documentation, please refer to the Javadoc of that method in the Mockito class. For stubbing Unit functions (or Java void methods) with throwables, see: Mockito.doThrow.
Return
OngoingStubbing object used to stub fluently. Do not create a reference to this returned object.
Parameters
method call to be stubbed.
Stubs a method/function call in a reverse manner, as part of a mock being created. You can reverse stub either synchronous as well as suspendable function calls.
Reverse stubbing is especially useful when stubbing a void method (or Unit function) to throw an exception.
Example:
mock<SynchronousFunctions> {
doThrow(RuntimeException()).on { string("test") }
}This function is an alias for whenever. Please use whenever instead.
Parameters
(regular or suspendable) lambda, wrapping the method/function call to be stubbed.