As far as I can see, there is no way to verify the order of method invocations on a mock.
Or am I missing something?
- (void)testResetCameraState_resetsCameraView
{
// Arrange
[given([_cameraManagerMock previewLayer]) willReturn:_testLayer];
// Act
[_cameraInteractor resetCameraState];
// Assert
[verifyCount(_cameraViewMock, times(1)) resetPreview];
[verifyCount(_cameraViewMock, times(1)) setPreviewLayer:_testLayer];
}
In this case you cannot verify, that the setPreviewLayer: is called after resetPreview.
I think I found a solution.
It's based on the
givenVoidmethod added in this pull request: https://github.com/jonreid/OCMockito/pull/93Sadly it is not merged yet, so you need to download and build this version by yourself: https://github.com/lysannschlegel/OCMockito/tree/given_void
With the new method you can verify the order of method calls in the following way:
This will reset the mock after the first call of
resetPreview.So we can verify stuff after that call:
resetPreviewis never called after the first call.setPreviewLayeris called after resetPreview.The
resetcall also resets thegivenVoid() willDo:so a secondresetcall wouldn't reset the mock again.Hope this helps, happy coding :D