I want to write a junit test with mockito
say this is my mock:
IServerApi routingServerApi = mock(ServerApi.class);
when(routingServerApi.sendRequest(anyString(), eq("request1"))).thenReturn(myObj1);
when(routingServerApi.sendRequest(anyString(), eq("request2"))).thenReturn(myObj2);
I want to verify that sendRequest
is called with request1
just before it's called with request2
(and no other invocation between them).
How can i do this?
I have seen this SOF question,
but I want to verify order of calls to just one mock, not two.
This syntax doesn't work for me (compilation error when initing inOrder()
)
InOrder inOrder = inOrder(mockRoutingServerApi);
inOrder.verify(mockRoutingServerApi).sendRtUpdates(time1, ImmutableList.of("update1"));
inOrder.verify(mockRoutingServerApi).sendRoutingRequest("request1");
inOrder.verify(mockRoutingServerApi).sendRtUpdates(time1, ImmutableList.of("update2"));
inOrder.verify(mockRoutingServerApi).sendRoutingRequest("request2");
Some commented I can use ArgumentCaptor
but I couldn't see how.
Aucun commentaire:
Enregistrer un commentaire