Package org.mockito
Interface InOrder
-
public interface InOrder
Allows verification in order. E.g:
As of Mockito 1.8.4 you can verifyNoMoreInteractions() in order-sensitive way. Read more:InOrder inOrder = inOrder(firstMock, secondMock); inOrder.verify(firstMock).add("was called first"); inOrder.verify(secondMock).add("was called second");
verifyNoMoreInteractions()
See examples in javadoc for
Mockito
class
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default void
verify(MockedStatic<?> mockedStatic, MockedStatic.Verification verification)
Verifies static interaction in order, with exactly one number of invocations.void
verify(MockedStatic<?> mockedStatic, MockedStatic.Verification verification, VerificationMode mode)
Verifies static interaction in order.<T> T
verify(T mock)
Verifies interaction happened once in order.<T> T
verify(T mock, VerificationMode mode)
Verifies interaction in order.void
verifyNoMoreInteractions()
Verifies that no more interactions happened in order.
-
-
-
Method Detail
-
verify
<T> T verify(T mock)
Verifies interaction happened once in order.Alias to
inOrder.verify(mock, times(1))
Example:
See examples in javadoc forInOrder inOrder = inOrder(firstMock, secondMock); inOrder.verify(firstMock).someMethod("was called first"); inOrder.verify(secondMock).someMethod("was called second");
Mockito
class- Parameters:
mock
- to be verified- Returns:
- mock object itself
-
verify
<T> T verify(T mock, VerificationMode mode)
Verifies interaction in order. E.g:
See examples in javadoc forInOrder inOrder = inOrder(firstMock, secondMock); inOrder.verify(firstMock, times(2)).someMethod("was called first two times"); inOrder.verify(secondMock, atLeastOnce()).someMethod("was called second at least once");
Mockito
class- Parameters:
mock
- to be verifiedmode
- for example times(x) or atLeastOnce()- Returns:
- mock object itself
-
verify
default void verify(MockedStatic<?> mockedStatic, MockedStatic.Verification verification)
Verifies static interaction in order, with exactly one number of invocations.
-
verify
void verify(MockedStatic<?> mockedStatic, MockedStatic.Verification verification, VerificationMode mode)
Verifies static interaction in order. E.g:try (MockedStatic
mocked = mockStatic(Foo.class)) { InOrder inOrder = inOrder(Foo.class); mocked.when(Foo::firstMethod).thenReturn("first"); mocked.when(Foo::secondMethod).thenReturn("second"); assertEquals("first", Foo.firstMethod()); assertEquals("second", Foo.secondMethod()); inOrder.verify(mocked, Foo::firstMethod, times(1)); inOrder.verify(mocked, Foo::secondMethod, atLeastOnce()); } - Parameters:
mockedStatic
- static mock to be verifiedverification
- verification to be verifiedmode
- for example times(x) or atLeastOnce()
-
verifyNoMoreInteractions
void verifyNoMoreInteractions()
Verifies that no more interactions happened in order. Different fromMockito.verifyNoMoreInteractions(Object...)
because the order of verification matters.Example:
mock.foo(); //1st mock.bar(); //2nd mock.baz(); //3rd InOrder inOrder = inOrder(mock); inOrder.verify(mock).bar(); //2n inOrder.verify(mock).baz(); //3rd (last method) //passes because there are no more interactions after last method: inOrder.verifyNoMoreInteractions(); //however this fails because 1st method was not verified: Mockito.verifyNoMoreInteractions(mock);
-
-