Thursday, 25 August 2016

Unit tests with mockito - how to verify that a parameter to a mock method call has an expected value

Use ArgumentCaptor, then in your verify() call for the method call you're setting up, use the argumentCaptor instead of the usual .class you'll be passing.

Then in your assert() to check the value, see if the argumentCaptor.getValue().get<field> has the value you're expecting

Basic idea is that you use ArgumentCaptor as the proxy to intercept the value the mock is getting.