Assuming message is mocked,
in the following case - the last verify
remembers to 2 before him?
So the number that supposed to be in times
is times(3)
?
when(message.hasMessages()).thenReturn(true);
assertTrue(message.hasMessages());
assertTrue(message.hasMessages());
verify(message, times(2)).hasMessages();
assertTrue(message.hasMessages());
verify(message, times(1)).hasMessages();
Mockito doesn't reset the invocation counter.
verify
counts all method invocations of a mock.So
verify(message, times(3)).hasMessages();
would be correct, becausehasMessages()
was invoked exactly 3 times.