what`s the scope of mockito verify?

624 views Asked by At

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();
1

There are 1 answers

0
Roland Weisleder On

Mockito doesn't reset the invocation counter. verify counts all method invocations of a mock.

So verify(message, times(3)).hasMessages(); would be correct, because hasMessages() was invoked exactly 3 times.