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