Mockito verify input parameter was called with a given value

Edit 23.04.2018
According to this issue, Mockito cannot capture var-args still.

There is a very easy way to verify a method has been called with the right parameter in Mockito. All you need to do is use captors, to capture the actual argument. Here is how you can use them:

 
ArgumentCaptor argument = ArgumentCaptor.forClass(RuleEntity.class);
 verify(mRulesRepository).createRule(argument.capture());
 assertEquals(1,argument.getValue().getRules().get(0).getTriggers().size())

Simple it is, just a quick reminder for starters.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s