public interface VerificationWithTimeout extends VerificationMode
VerificationMode
that allows combining existing verification modes with 'timeout'. E.g:
verify(mock, timeout(100).times(5)).foo();
verify(mock, timeout(100).never()).bar();
verify(mock, timeout(200).atLeastOnce()).baz();
This is similar to after()
except this assertion will immediately pass if it becomes true at any point,
whereas after() will wait the full period. Assertions which are consistently expected to be initially true and potentially become false
are deprecated below, and after() should be used instead.
See examples in javadoc for Mockito.verify(Object, VerificationMode)
Modifier and Type | Method and Description |
---|---|
VerificationMode |
atLeast(int minNumberOfInvocations)
Allows at-least-x verification within given timeout.
|
VerificationMode |
atLeastOnce()
Allows at-least-once verification within given timeout.
|
VerificationMode |
atMost(int maxNumberOfInvocations)
Deprecated.
Deprecated
Validation with timeout combined with never simply does not make sense, as atMost() will typically immediately pass,
and therefore not wait the timeout. The behaviour you may be looking for is actually provided by after().atMost().
To avoid compilation errors upon upgrade the method is deprecated and it throws a "friendly reminder" exception. In a future release we will remove timeout(x).atMost(y) and timeout(x).never() from the API. Do you want to find out more? See issue 235 |
VerificationMode |
never()
Deprecated.
Validation with timeout combined with never simply does not make sense, as never() will typically immediately pass,
and therefore not wait the timeout. The behaviour you may be looking for is actually provided by after().never().
To avoid compilation errors upon upgrade the method is deprecated and it throws a "friendly reminder" exception. In a future release we will remove timeout(x).atMost(y) and timeout(x).never() from the API. Do you want to find out more? See issue 235 |
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
|
verify
VerificationMode times(int wantedNumberOfInvocations)
verify(mock, timeout(100).times(2)).someMethod("some arg");
See examples in javadoc for Mockito
classwantedNumberOfInvocations
- wanted number of invocations@Deprecated VerificationMode never()
To avoid compilation errors upon upgrade the method is deprecated and it throws a "friendly reminder" exception.
In a future release we will remove timeout(x).atMost(y) and timeout(x).never() from the API.
Do you want to find out more? See issue 235
VerificationMode atLeastOnce()
verify(mock, timeout(100).atLeastOnce()).someMethod("some arg");
Alias to atLeast(1)
See examples in javadoc for Mockito
class
VerificationMode atLeast(int minNumberOfInvocations)
verify(mock, timeout(100).atLeast(3)).someMethod("some arg");
See examples in javadoc for Mockito
classminNumberOfInvocations
- minimum number of invocations@Deprecated VerificationMode atMost(int maxNumberOfInvocations)
To avoid compilation errors upon upgrade the method is deprecated and it throws a "friendly reminder" exception.
In a future release we will remove timeout(x).atMost(y) and timeout(x).never() from the API.
Do you want to find out more? See issue 235
VerificationMode only()
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