Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to verify a method is called two times with mockito verify()

I want to verify if a method is called at least once through mockito verify. I used verify and it complains like this:

org.mockito.exceptions.verification.TooManyActualInvocations:  Wanted 1 time: But was 2 times. Undesired invocation: 
like image 862
Ahmad Beg Avatar asked Feb 15 '13 07:02

Ahmad Beg


1 Answers

Using the appropriate VerificationMode:

import static org.mockito.Mockito.atLeast; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify;  verify(mockObject, atLeast(2)).someMethod("was called at least twice"); verify(mockObject, times(3)).someMethod("was called exactly three times"); 
like image 152
Liosan Avatar answered Sep 29 '22 06:09

Liosan