dimanche 1 mars 2020

[Mockito] verify order / sequence of method calls

Exemple d'utilsation de InOrder :
@Mock ServiceClassA firstMock;
@Mock ServiceClassB secondMock;

doNothing().when(firstMock).methodOne();   
doNothing().when(secondMock).methodTwo();  

//create inOrder object passing any mocks that need to be verified in order
InOrder inOrder = inOrder(firstMock, secondMock);

//following will make sure that firstMock was called before secondMock
inOrder.verify(firstMock).methodOne();
inOrder.verify(secondMock).methodTwo();
https://stackoverflow.com/questions/21901368/mockito-verify-order-sequence-of-method-calls

Aucun commentaire:

Enregistrer un commentaire

to criticize, to improve