I want to use Mockito to test the (simplified) code below. I do not know how to tell Mokito a failure the first time, and then succeed a second time.
for(int i = 1; i < 3; i++) { String ret = myMock.doTheCall(); if("Success".equals(ret)) { log.write("success"); } else if ( i < 3 ) { log.write("failed, but I'll try again. attempt: " + i); } else { throw new FailedThreeTimesException(); } }
I can set up a success test with:
Mockito.when(myMock).doTheCall().thenReturn("Success");
And the test with an error:
Mockito.when(myMock).doTheCall().thenReturn("you failed");
But how can I verify that if it works once (or twice), then it will succeed?
java mockito
jb. Aug 2 2018-12-12T00: 00Z
source share