mockito-kotlin icon indicating copy to clipboard operation
mockito-kotlin copied to clipboard

Infix extension function for doReturn stub construction

Open RobertZagorski opened this issue 7 years ago • 1 comments
trafficstars

Mockito provides 2 constructions for stubbing: doReturn(...).when(...) when(...).thenReturn(...) The first one is known not to call real method, which is sometimes handy (source) There are nice extensions for the second use case, which allow for more concise writing of stubbing:

search.stub {
     on { what } doReturn WHAT
}

It would be nice to provide consise construction for the first use case:

search.stub {
     doReturn { WHAT } on { what}
}

Those examples are of course very basic, but it would become more helpful in more advanced use cases. Basically what is needed is providing method doReturn function in KStubbing interface and infix extension function called on to OngoingStubbing interface, I guess.

I hope you see my point

RobertZagorski avatar Jun 12 '18 07:06 RobertZagorski

You can use lambda with doAnswer. Is it not enough?

search.stub {
    on { what } doAnswer { WHAT }
}

glureau-betclic avatar Dec 03 '19 10:12 glureau-betclic