Using Mockito, I need to test a method that gets called twice in the same transaction and returns different values each time.
I have two tests - one for each call.
The first is:
verify(mockAppender, times(2)).doAppend(logEventArgumentCaptor.capture());
assertThat(logEventArgumentCaptor.getValue().getMessage(), containsString("Error response: " + RESPONSE ));
whilst the 2nd reads:
verify(mockAppender, times(2)).doAppend(logEventArgumentCaptor.capture());
assertThat(logEventArgumentCaptor.getValue().getMessage(), containsString("Request body: " + BODY));
The code being tested reads:
if (!statusCode.is2xxSuccessful()) {
LOG.error("Error response: "+response);
LOG.error("Request body: "+bodyString);
}
The 2nd test passes because it finds the 2nd response, but the 1st fails because it also finds the 2nd response. How can I get the first test to look only at the first response from the method? Or is there a form of assertThat that would allow me to check both responses at once?