I'm playing with the rxjava vert.x (ver. 3.8.4) WebClient. My client will call some services so, by Mockito (ver. 3.2.4) I'm testing how it should handle an error. Here is how I mock the service's response:
...
JsonObject jsonResponse = new JsonObject();
HttpResponse<Buffer> httpResponse = Mockito.mock(HttpResponse.class);
Mockito.when(httpResponse.statusCode()).thenReturn(500);
Mockito.when(httpResponse.bodyAsJsonObject()).thenReturn(jsonResponse);
HttpRequest<Buffer> httpRequest = Mockito.mock(HttpRequest.class);
Mockito.when(httpRequest.rxSend()).thenReturn(Single.just(httpResponse));
return httpRequest;
...
as the Mockito.when(httpResponse.statusCode()).thenReturn(500);
is executed I get this error:
org.mockito.exceptions.misusing.UnfinishedStubbingException:
Unfinished stubbing detected here:
-> at my.dummy.project.ServiceHandlerTest.serviceRepliesWithA500Response(ServiceHandlerTest.java:70)
E.g. thenReturn() may be missing.
Examples of correct stubbing:
when(mock.isOk()).thenReturn(true);
when(mock.isOk()).thenThrow(exception);
doThrow(exception).when(mock).someVoidMethod();
Hints:
1. missing thenReturn()
2. you are trying to stub a final method, which is not supported
3. you are stubbing the behaviour of another mock inside before 'thenReturn' instruction is completed
...
What am I missing here?