I have a method of a mocked object that can be called multiple times (think recursion). The method is defined like this:
public void doCommit() { }
In order to tell it to fail I use this convention:
doThrow(new RuntimeException()).when(mMockedObject).doCommit();
This though, makes the method throw this exception EVERY time it is called. How can I make it so that it only, for example, throws it the first and third time it is called? Which means that, for example, the second and forth time it just returns without throwing an exception. Please note that I am not the author of doCommit(), nor do I have source code that I can change.