1 /*
2  * Copyright (c) 2007 Mockito contributors
3  * This program is made available under the terms of the MIT License.
4  */
5 package org.mockitousage.misuse;
6 
7 import org.junit.Test;
8 import org.mockito.InOrder;
9 import org.mockito.Mock;
10 import org.mockito.exceptions.misusing.MissingMethodInvocationException;
11 import org.mockitousage.IMethods;
12 import org.mockitoutil.TestBase;
13 
14 import static org.junit.Assert.fail;
15 import static org.mockito.Mockito.*;
16 
17 public class CleaningUpPotentialStubbingTest extends TestBase {
18 
19     @Mock private IMethods mock;
20 
21     @Test
shouldResetOngoingStubbingOnVerify()22     public void shouldResetOngoingStubbingOnVerify() {
23         // first test
24         mock.booleanReturningMethod();
25         verify(mock).booleanReturningMethod();
26 
27         // second test
28         assertOngoingStubbingIsReset();
29     }
30 
31     @Test
shouldResetOngoingStubbingOnInOrder()32     public void shouldResetOngoingStubbingOnInOrder() {
33         mock.booleanReturningMethod();
34         InOrder inOrder = inOrder(mock);
35         inOrder.verify(mock).booleanReturningMethod();
36         assertOngoingStubbingIsReset();
37     }
38 
39     @Test
shouldResetOngoingStubbingOnDoReturn()40     public void shouldResetOngoingStubbingOnDoReturn() {
41         mock.booleanReturningMethod();
42         doReturn(false).when(mock).booleanReturningMethod();
43         assertOngoingStubbingIsReset();
44     }
45 
assertOngoingStubbingIsReset()46     private void assertOngoingStubbingIsReset() {
47         try {
48             //In real, there might be a call to real object or a final method call
49             //I'm modelling it with null
50             when(null).thenReturn("anything");
51             fail();
52         } catch (MissingMethodInvocationException e) {}
53     }
54 }
55