title: Forming Mockito "grammars"
body: <p>Mockito seems like a pretty sweet stubbing/mocking framework for Java. The only problem is I can't find any concrete documentation on the best ways of using their API. Common methods used in tests include:</p>
  <pre><code>doXXX(???) : Stubber
  when(T) : OngoingStubbing
  then(T) : OngoingStubbing
  verify(???) : T
  given(T) : BDDOngoingStubbing
  willXXX(???) : BDDStubber
  </code></pre>
  <p>When you see examples of Mockito in practice, you see code like:</p>
  <pre><code>when(yourMethod()).thenReturn(5);
  </code></pre>
  <p>From all the docs I've read, I've identified several &quot;patterns&quot; of Mockito &quot;grammars&quot; obtained from daisy-chaining these method calls together like the example above. Some common patterns I've found are:</p>
  <blockquote>
  <p><strong>When/Then:</strong> when(yourMethod()).thenReturn(5);</p>
  <p><strong>Given/Will:</strong> given(yourMethod()).willThrow(OutOfMemoryException.class);</p>
  <p><strong>Do/When:</strong> doReturn(7).when(yourMock.fizzBuzz());</p>
  <p><strong>Will/Given/Do:</strong> willReturn(any()).given(yourMethod()).doNothing();</p>
  <p><strong>Verify/Do:</strong> verify(yourMethod()).doThrow(SomeException.class);</p>
  </blockquote>
  <p>What I'm choking on is how to select the right pattern/combination of method calls to model my test cases. It seems like you can daisy-chain these together in seemingly endless combos and I'm not sure what pattern is right for which problem.</p>
  <p>Can some Mockito Guru help shed some light as to which patterns/combinations of Mockito methods are used for which types of test cases (and why)? Thanks in advance!</p>