Closed dalewking closed 2 weeks ago
I like the idea, but I would adjust the naming:
every { mock.findById(any()) } returnsBy ::book
every { mock.findById(any()) } returnsSuccessBy ::book
every { mock.findById(any()) } returnsFailureBy ::IllegalStateException
every { mock.findById(any()) } throwsBy ::IllegalStateException
It's implemented. It will be available with the next release.
I have a lot of boilerplate mocks set up like this where I have a bunch of var properties defining the data which can then be modified and then would like to use returns/returnsSuccess with the property instead of call.
So using the example from the docs it currently looks something like this:
reading the code it doesn't really represent what it is doing. calls is only used because we need to get the current value of the property. And when the return value is result there is no callsSuccess
So my thought would be that there would be overloads of returns/returnsSuccess that instead of a value of type T take a lambda of type
() -> T
Then one could instead say something more like
or
and for the case where the type is a
Result