Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you can fully specify the sequence of calls that will happen on your mock, then you won't need a <code>beforeAnyOther</code> verification mode. For example, assuming your desired behavior is...</p> <ul> <li><code>begin</code> gets called once, then</li> <li><code>end</code> gets called once, then</li> <li><code>flush</code> gets called once</li> <li>no other calls are made on <code>tool</code></li> </ul> <p>then the following should the job:</p> <pre><code>// Verify that the three invocations arrived in the desired order. InOrder inOrder = inOrder(tool); inOrder.verify(tool).begin(); inOrder.verify(tool).end(); inOrder.verify(tool).flush(); // Verify that the three invocations are all we received. Mockito.verify(tool).begin(); Mockito.verify(tool).end(); Mockito.verify(tool).flush(); Mockito.verifyNoMoreInteractions(); </code></pre> <p>On the other hand, if you have any additional calls that happen outside of the sequence you wish to verify then you're correct, Mockito can't verify that at present. So for example, if you knew you had to call <code>tool.setPenColor()</code> at some point between <code>begin</code> and <code>flush</code> but it didn't matter if this call came before or after the call to <code>end</code>, you'd be out of luck.</p> <p>You can handle this situation in some other mocking libraries. EasyMock makes this easiest - for example, for a sequence where <code>begin</code> comes first, <code>flush</code> comes last, and we don't care about the calls in the middle:</p> <pre><code>DrawTool mock = EasyMock.createMock(DrawTool.class); EasyMock.checkOrder(mock, true); mock.begin(); EasyMock.expectLastCall(); EasyMock.checkOrder(mock, false); mock.end(); EasyMock.expectLastCall(); EasyMock.expect(mock.someOtherCallThatReturnsAValue()).andReturn(null); EasyMock.checkOrder(mock, true); mock.flush(); EasyMock.expectLastCall(); EasyMock.replay(mock); new Drawer().draw(tool); EasyMock.verify(mock); </code></pre> <p>An equivalent test appears to be possible, if unwieldy, in JMock 2. It's a <a href="http://jmock.org/javadoc/jmock-1.2.0/org/jmock/builder/IdentityBuilder.html#id%28java.lang.String%29" rel="nofollow">bit</a> <a href="http://jmock.org/javadoc/jmock-1.2.0/org/jmock/builder/MatchBuilder.html#after%28java.lang.String%29" rel="nofollow">easier</a> in JMock 1, but that library is antiquated (circa JDK 1.3), so don't use it. This isn't possible in Moxie (disclaimer/shameless plug: I'm the author), but there's now a <a href="https://code.google.com/p/moxiemocks/issues/detail?id=21" rel="nofollow">todo list item</a> for that.</p> <p>I can't speak for the Mockito devs as to why the Mockito verification API docs are the way they are - best ask them on the mailing list. I'm sure they'd welcome a patch.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload