19 Kasım 2019 Salı

Mockito InOrder Arayüzü

constructor
Şöyle yaparız
Foo mockFoo = Mockito.mock(Foo.class);
InOrder orderVerifier = Mockito.inOrder(mockFoo);
verify metodu
Örnek
Şöyle yaparız.
ServiceClassA firstMock = mock(ServiceClassA.class);
ServiceClassB secondMock = mock(ServiceClassB.class);

Mockito.doNothing().when(firstMock).methodOne();   
Mockito.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();
Örnek
Şöyle yaparız.
InOrder inOrder = Mockito.inOrder(mock);
inOrder.verify(mock).addPost(any(Post.class));
inOrder.verify(mock).getAllPosts();

Hiç yorum yok:

Yorum Gönder