• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2007 Mockito contributors
3  * This program is made available under the terms of the MIT License.
4  */
5 
6 package org.mockito;
7 
8 import org.mockito.verification.VerificationMode;
9 
10 /**
11  * Allows verification in order. E.g:
12  *
13  * <pre class="code"><code class="java">
14  * InOrder inOrder = inOrder(firstMock, secondMock);
15  *
16  * inOrder.verify(firstMock).add("was called first");
17  * inOrder.verify(secondMock).add("was called second");
18  * </code></pre>
19  *
20  * As of Mockito 1.8.4 you can verifyNoMoreInteractions() in order-sensitive way. Read more: {@link InOrder#verifyNoMoreInteractions()}
21  * <p>
22  *
23  * See examples in javadoc for {@link Mockito} class
24  */
25 public interface InOrder {
26     /**
27      * Verifies interaction <b>happened once</b> in order.
28      * <p>
29      * Alias to <code>inOrder.verify(mock, times(1))</code>
30      * <p>
31      * Example:
32      * <pre class="code"><code class="java">
33      * InOrder inOrder = inOrder(firstMock, secondMock);
34      *
35      * inOrder.verify(firstMock).someMethod("was called first");
36      * inOrder.verify(secondMock).someMethod("was called second");
37      * </code></pre>
38      *
39      * See examples in javadoc for {@link Mockito} class
40      *
41      * @param mock to be verified
42      *
43      * @return mock object itself
44      */
verify(T mock)45     <T> T verify(T mock);
46 
47     /**
48      * Verifies interaction in order. E.g:
49      *
50      * <pre class="code"><code class="java">
51      * InOrder inOrder = inOrder(firstMock, secondMock);
52      *
53      * inOrder.verify(firstMock, times(2)).someMethod("was called first two times");
54      * inOrder.verify(secondMock, atLeastOnce()).someMethod("was called second at least once");
55      * </code></pre>
56      *
57      * See examples in javadoc for {@link Mockito} class
58      *
59      * @param mock to be verified
60      * @param mode for example times(x) or atLeastOnce()
61      *
62      * @return mock object itself
63      */
verify(T mock, VerificationMode mode)64     <T> T verify(T mock, VerificationMode mode);
65 
66 
67     /**
68      * Verifies that no more interactions happened <b>in order</b>.
69      * Different from {@link Mockito#verifyNoMoreInteractions(Object...)} because the order of verification matters.
70      * <p>
71      * Example:
72      * <pre class="code"><code class="java">
73      * mock.foo(); //1st
74      * mock.bar(); //2nd
75      * mock.baz(); //3rd
76      *
77      * InOrder inOrder = inOrder(mock);
78      *
79      * inOrder.verify(mock).bar(); //2n
80      * inOrder.verify(mock).baz(); //3rd (last method)
81      *
82      * //passes because there are no more interactions after last method:
83      * inOrder.verifyNoMoreInteractions();
84      *
85      * //however this fails because 1st method was not verified:
86      * Mockito.verifyNoMoreInteractions(mock);
87      * </code></pre>
88      */
verifyNoMoreInteractions()89     void verifyNoMoreInteractions();
90 }
91