Skip to content

Commit

Permalink
Improve examples for InOrder (#2843)
Browse files Browse the repository at this point in the history
Include some context in InOrder examples and add an example that uses
a static mock as well.
ascopes authored Jan 15, 2023
1 parent 484de45 commit f2a47c3
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion src/main/java/org/mockito/InOrder.java
Original file line number Diff line number Diff line change
@@ -12,13 +12,41 @@
* Allows verification in order. E.g:
*
* <pre class="code"><code class="java">
* // Given
* First firstMock = mock(First.class);
* Second secondMock = mock(Second.class);
* InOrder inOrder = inOrder(firstMock, secondMock);
*
* // When
* firstMock.add("was called first");
* secondMock.add("was called second");
*
* // Then
* inOrder.verify(firstMock).add("was called first");
* inOrder.verify(secondMock).add("was called second");
* inOrder.verifyNoMoreInteractions();
* </code></pre>
*
* Static mocks can be verified alongside non-static mocks. E.g:
*
* <pre class="code"><code class="java">
* // Given
* First firstMock = mock(First.class);
* MockedStatic<StaticSecond> staticSecondMock = mockStatic(StaticSecond.class);
* InOrder inOrder = inOrder(firstMock, StaticSecond.class);
*
* // When
* firstMock.add("was called first");
* StaticSecond.doSomething("foobar");
*
* // Then
* inOrder.verify(firstMock).add("was called first");
* inOrder.verify(staticSecondMock, () -&gt; StaticSecond.doSomething("foobar"));
* inOrder.verifyNoMoreInteractions();
* </code></pre>
*
* As of Mockito 1.8.4 you can verifyNoMoreInteractions() in order-sensitive way. Read more: {@link InOrder#verifyNoMoreInteractions()}
* As of Mockito 1.8.4 you can verifyNoMoreInteractions() in order-sensitive way. Read more:
* {@link InOrder#verifyNoMoreInteractions()}.
* <p>
*
* See examples in javadoc for {@link Mockito} class

0 comments on commit f2a47c3

Please sign in to comment.