0

Is there any way to mock something like this:

when(mock.methodCall(Class::gettter)).willReturn(...)
when(mock.methodCall(Class::gettter2)).willReturn(...)

Header for methodCall

methodCall(Function<Class, String> function)

When I use ArgumentMatchers.eq(...) mock does not return value from willReturn

LuCio
  • 5,055
  • 2
  • 18
  • 34
Krzysztof Mazur
  • 568
  • 2
  • 13
  • 1
    A method reference `Class::gettter` may return every time a new `Function`. Only ["two lambdas that are reference-equal (==) are going to compute the same function"](https://stackoverflow.com/a/24098805/2838289). – LuCio Nov 28 '18 at 14:23
  • It looks like you're trying to mock the wrong thing. You're starting to create a complex mocking logic. A better question would be - why can't the mock use the `Function` passed into it? Look at how you can `doAnswer`, where your mocking code makes use of the inputs to the mock object to calculate a fake answer, rather than just use a list of pre-ordained answers. To advise you more, why don't you post more of the code you're trying to test and the test scenario you're trying to achieve. – Ashley Frieze Dec 01 '18 at 11:21

0 Answers0