Enhance/unify and document stubbing API, more groundwork towards implementing improved suspend function support #556
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR is another step of improving suspend function support in Mockito-Kotlin as discussed in #553.
This PR specifically focusses on documenting the stubbing API in Mockito-Kotlin, as well as unifying the various stubbing methods towords a unified model:
whenever(mock.methodCall())/whenever(mock).methodCall()/whenever { mock.methodCall() }oron(mock.methodCall())/on { mock.methodCall() }; these methods supply universal support for synchronous and suspendable methods/functios, as well as support for methods/function stubs with generics return types.wheneverBlocking { mock.methodCall() }andonBlocking { mock.methodCall() }have been declared deprecated to unify towards the abovementioned stubbing functionswhenever { mock.methodCall() }andon { mock.methodCall() }.onGeneric { mock.methodCall() }have been deprecated in favor ofon { mock.methodCall() }.The unit tests now tend more towards applying a notation with lambdas for specifying methodCalls and answer specification, using infix notation where posible, e.g.:
This signifies a move away from mere aliasing/casting functions on top of classic Mockito syntax, towards a more idiomtic Kotlin syntax to stub mocks. More prominent application of lamdas allows us to let the stubbing API evolve in the direction of a clean mocking DSL. This universal idiomtic Kotlin syntax is fully leveraging the powers of lambdas, infix functions, and reified generics in inline functions.
But of course, all alternative notations still apply and are covered with unit tests as well to demonstrate these alternative notations.