12637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffinpackage org.mockitousage.basicapi; 22637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin 32637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffinimport org.junit.Test; 42637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffinimport org.mockito.Mock; 52637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffinimport org.mockito.exceptions.misusing.NotAMockException; 62637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffinimport org.mockitousage.IMethods; 72637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffinimport org.mockitoutil.TestBase; 82637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin 92637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffinimport static junit.framework.TestCase.assertEquals; 102637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffinimport static org.mockito.Mockito.*; 112637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin 122637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffinpublic class ResetInvocationsTest extends TestBase { 132637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin 142637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin @Mock 152637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin IMethods methods; 162637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin 172637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin @Mock 182637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin IMethods moarMethods; 192637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin 202637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin @Test 212637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin public void reset_invocations_should_reset_only_invocations() { 222637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin when(methods.simpleMethod()).thenReturn("return"); 232637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin 242637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin methods.simpleMethod(); 252637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin verify(methods).simpleMethod(); 262637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin 272637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin clearInvocations(methods); 282637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin 292637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin verifyNoMoreInteractions(methods); 302637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin assertEquals("return", methods.simpleMethod()); 312637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin } 322637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin 332637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin @Test 342637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin public void should_reset_invocations_on_multiple_mocks() { 352637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin methods.simpleMethod(); 362637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin moarMethods.simpleMethod(); 372637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin 382637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin clearInvocations(methods, moarMethods); 392637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin 402637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin verifyNoMoreInteractions(methods, moarMethods); 412637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin } 422637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin 432637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin @Test(expected = NotAMockException.class) 442637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin public void resettingNonMockIsSafe() { 452637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin clearInvocations(""); 462637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin } 472637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin 482637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin @Test(expected = NotAMockException.class) 492637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin public void resettingNullIsSafe() { 502637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin clearInvocations(new Object[]{null}); 512637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin } 522637d96c202372854a7c71466ddcc6e90fc4fc53Paul Duffin} 53