Skip to content

Commit f2a47c3

Browse files
authored
Improve examples for InOrder (#2843)
Include some context in InOrder examples and add an example that uses a static mock as well.
1 parent 484de45 commit f2a47c3

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

src/main/java/org/mockito/InOrder.java

+29-1
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,41 @@
1212
* Allows verification in order. E.g:
1313
*
1414
* <pre class="code"><code class="java">
15+
* // Given
16+
* First firstMock = mock(First.class);
17+
* Second secondMock = mock(Second.class);
1518
* InOrder inOrder = inOrder(firstMock, secondMock);
1619
*
20+
* // When
21+
* firstMock.add("was called first");
22+
* secondMock.add("was called second");
23+
*
24+
* // Then
1725
* inOrder.verify(firstMock).add("was called first");
1826
* inOrder.verify(secondMock).add("was called second");
27+
* inOrder.verifyNoMoreInteractions();
28+
* </code></pre>
29+
*
30+
* Static mocks can be verified alongside non-static mocks. E.g:
31+
*
32+
* <pre class="code"><code class="java">
33+
* // Given
34+
* First firstMock = mock(First.class);
35+
* MockedStatic<StaticSecond> staticSecondMock = mockStatic(StaticSecond.class);
36+
* InOrder inOrder = inOrder(firstMock, StaticSecond.class);
37+
*
38+
* // When
39+
* firstMock.add("was called first");
40+
* StaticSecond.doSomething("foobar");
41+
*
42+
* // Then
43+
* inOrder.verify(firstMock).add("was called first");
44+
* inOrder.verify(staticSecondMock, () -&gt; StaticSecond.doSomething("foobar"));
45+
* inOrder.verifyNoMoreInteractions();
1946
* </code></pre>
2047
*
21-
* As of Mockito 1.8.4 you can verifyNoMoreInteractions() in order-sensitive way. Read more: {@link InOrder#verifyNoMoreInteractions()}
48+
* As of Mockito 1.8.4 you can verifyNoMoreInteractions() in order-sensitive way. Read more:
49+
* {@link InOrder#verifyNoMoreInteractions()}.
2250
* <p>
2351
*
2452
* See examples in javadoc for {@link Mockito} class

0 commit comments

Comments
 (0)