I’m calling a method on a mock in a service I am testing.
The mock is a class for updating database data, I want to verify that the update method is called.
The code looks like this:
verify(updateLockedAccountStatusMock, times(1)).update(1, 3, true, new Date());
I know this can’t work, since the Date
object that is passed into the mock in the class under test is generated in the class just before the method is called. I also know that I can’t call any()
here unless I call any()
for every parameter. I’d rather not do that as the same method is called elsewhere in the code.
Is there a way to handle cases like this? Or is it simply a matter of passing in any()
for every parameter and verifying the amount of times it’s called?
In particular I want to see that the third parameter true
is correct, but the date is the only one I don’t really care about at the moment.
>Solution :
You can use any()
for one argument and other matchers (such as eq
) for the other arguments.
verify(updateLockedAccountStatusMock, times(1)).update(eq(1), eq(3), eq(true), any());