1 /*
2  * Copyright (c) 2007 Mockito contributors
3  * This program is made available under the terms of the MIT License.
4  */
5 
6 package org.mockito.internal.progress;
7 
8 import org.junit.Before;
9 import org.junit.Test;
10 import org.mockito.exceptions.base.MockitoException;
11 import org.mockito.internal.verification.VerificationModeFactory;
12 import org.mockito.verification.VerificationMode;
13 import org.mockitoutil.TestBase;
14 
15 import static org.junit.Assert.*;
16 
17 public class MockingProgressImplTest extends TestBase {
18 
19     private MockingProgress mockingProgress;
20 
21     @Before
setup()22     public void setup() {
23         mockingProgress = new MockingProgressImpl();
24     }
25 
26     @Test
shouldStartVerificationAndPullVerificationMode()27     public void shouldStartVerificationAndPullVerificationMode() throws Exception {
28         assertNull(mockingProgress.pullVerificationMode());
29 
30         VerificationMode mode = VerificationModeFactory.times(19);
31 
32         mockingProgress.verificationStarted(mode);
33 
34         assertSame(mode, mockingProgress.pullVerificationMode());
35 
36         assertNull(mockingProgress.pullVerificationMode());
37     }
38 
39     @Test
shouldCheckIfVerificationWasFinished()40     public void shouldCheckIfVerificationWasFinished() throws Exception {
41         mockingProgress.verificationStarted(VerificationModeFactory.atLeastOnce());
42         try {
43             mockingProgress.verificationStarted(VerificationModeFactory.atLeastOnce());
44             fail();
45         } catch (MockitoException e) {}
46     }
47 
48     @Test
shouldNotifyListenerSafely()49     public void shouldNotifyListenerSafely() throws Exception {
50         //when
51         mockingProgress.addListener(null);
52 
53         //then no exception is thrown:
54         mockingProgress.mockingStarted(null, null);
55     }
56 }
57