title: How to throw an exception upon first invocation and a regular return value on the second?
body: <p>My code makes network calls. Sometimes these fail and I've implemented some <a href="https://pub.dev/packages/retry" rel="nofollow noreferrer">retry</a> logic. Now I wish to test this with a unit test. I'm using <a href="https://pub.dev/packages/mockito" rel="nofollow noreferrer">Mockito</a> for this. I'm having trouble mocking this particular method call, this is my test code:</p>
  
  <pre><code>var mock = MockHttpClient();
  var answers = &lt;Future&lt;String&gt;&gt;[
    Future.error(Exception('boom')),
    Future.value('some return value'),
  ];
  when(mock.getStuff()).thenAnswer((_) =&gt; answers.removeAt(0));
  
  var client = Client(inner: mock);
  
  var result = client.someCall(); // This method call uses the `inner` object to make the `getStuff` network call.
  expect(result, 'some return value');
  </code></pre>
  
  <p>Running this code throws an exception. And I get that because of the first returned <code>Future</code>! Mockito has the appropriate method call named <a href="https://pub.dev/documentation/mockito/latest/mockito/PostExpectation/thenThrow.html" rel="nofollow noreferrer"><code>thenThrow</code></a> but I can't figure out how to combine the two.</p>