1 package org.mockitousage.basicapi; 2 3 import org.junit.Test; 4 import org.mockito.Mock; 5 import org.mockito.exceptions.misusing.NotAMockException; 6 import org.mockitousage.IMethods; 7 import org.mockitoutil.TestBase; 8 9 import static junit.framework.TestCase.assertEquals; 10 import static org.mockito.Mockito.*; 11 12 public class ResetInvocationsTest extends TestBase { 13 14 @Mock 15 IMethods methods; 16 17 @Mock 18 IMethods moarMethods; 19 20 @Test reset_invocations_should_reset_only_invocations()21 public void reset_invocations_should_reset_only_invocations() { 22 when(methods.simpleMethod()).thenReturn("return"); 23 24 methods.simpleMethod(); 25 verify(methods).simpleMethod(); 26 27 clearInvocations(methods); 28 29 verifyNoMoreInteractions(methods); 30 assertEquals("return", methods.simpleMethod()); 31 } 32 33 @Test should_reset_invocations_on_multiple_mocks()34 public void should_reset_invocations_on_multiple_mocks() { 35 methods.simpleMethod(); 36 moarMethods.simpleMethod(); 37 38 clearInvocations(methods, moarMethods); 39 40 verifyNoMoreInteractions(methods, moarMethods); 41 } 42 43 @Test(expected = NotAMockException.class) resettingNonMockIsSafe()44 public void resettingNonMockIsSafe() { 45 clearInvocations(""); 46 } 47 48 @Test(expected = NotAMockException.class) resettingNullIsSafe()49 public void resettingNullIsSafe() { 50 clearInvocations(new Object[]{null}); 51 } 52 } 53