org.mockito.verification
Class Timeout

java.lang.Object
  extended by org.mockito.verification.Timeout
All Implemented Interfaces:
VerificationMode, VerificationWithTimeout

public class Timeout
extends java.lang.Object
implements VerificationWithTimeout

See the javadoc for VerificationWithTimeout


Constructor Summary
Timeout(int millis, VerificationMode delegate)
          See the javadoc for VerificationWithTimeout
 
Method Summary
 VerificationMode atLeast(int minNumberOfInvocations)
          Allows at-least-x verification withing given timeout.
 VerificationMode atLeastOnce()
          Allows at-least-once verification withing given timeout.
 VerificationMode atMost(int maxNumberOfInvocations)
          Allows at-most-x verification within given timeout.
 VerificationMode never()
          Alias to times(0), see VerificationWithTimeout.times(int)
 VerificationMode only()
          Allows checking if given method was the only one invoked.
 VerificationMode times(int wantedNumberOfInvocations)
          Allows verifying exact number of invocations within given timeout
 void verify(VerificationData data)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Timeout

public Timeout(int millis,
               VerificationMode delegate)
See the javadoc for VerificationWithTimeout

Method Detail

verify

public void verify(VerificationData data)
Specified by:
verify in interface VerificationMode

atLeast

public VerificationMode atLeast(int minNumberOfInvocations)
Description copied from interface: VerificationWithTimeout
Allows at-least-x verification withing given timeout. E.g:
   verify(mock, timeout(100).atLeast(3)).someMethod("some arg");
 
See examples in javadoc for Mockito class

Specified by:
atLeast in interface VerificationWithTimeout
Parameters:
minNumberOfInvocations - minimum number of invocations
Returns:
verification mode

atLeastOnce

public VerificationMode atLeastOnce()
Description copied from interface: VerificationWithTimeout
Allows at-least-once verification withing given timeout. E.g:
   verify(mock, timeout(100).atLeastOnce()).someMethod("some arg");
 
Alias to atLeast(1)

See examples in javadoc for Mockito class

Specified by:
atLeastOnce in interface VerificationWithTimeout
Returns:
verification mode

atMost

public VerificationMode atMost(int maxNumberOfInvocations)
Description copied from interface: VerificationWithTimeout
Allows at-most-x verification within given timeout. E.g:
   verify(mock, timeout(100).atMost(3)).someMethod("some arg");
 
See examples in javadoc for Mockito class

Specified by:
atMost in interface VerificationWithTimeout
Parameters:
maxNumberOfInvocations - max number of invocations
Returns:
verification mode

never

public VerificationMode never()
Description copied from interface: VerificationWithTimeout
Alias to times(0), see VerificationWithTimeout.times(int)

Verifies that interaction did not happen within given timeout. E.g:

   verify(mock, timeout(100).never()).someMethod();
 

If you want to verify there were NO interactions with the mock check out Mockito.verifyNoMoreInteractions(Object...)

See examples in javadoc for Mockito class

Specified by:
never in interface VerificationWithTimeout
Returns:
verification mode

only

public VerificationMode only()
Description copied from interface: VerificationWithTimeout
Allows checking if given method was the only one invoked. E.g:
   verify(mock, only()).someMethod();
   //above is a shorthand for following 2 lines of code:
   verify(mock).someMethod();
   verifyNoMoreInvocations(mock);
 

See also Mockito.verifyNoMoreInteractions(Object...)

See examples in javadoc for Mockito class

Specified by:
only in interface VerificationWithTimeout
Returns:
verification mode

times

public VerificationMode times(int wantedNumberOfInvocations)
Description copied from interface: VerificationWithTimeout
Allows verifying exact number of invocations within given timeout
   verify(mock, timeout(100).times(2)).someMethod("some arg");
 
See examples in javadoc for Mockito class

Specified by:
times in interface VerificationWithTimeout
Parameters:
wantedNumberOfInvocations - wanted number of invocations
Returns:
verification mode