• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 static org.junit.Assert.fail;
8 import static org.mockito.ArgumentMatchers.any;
9 import static org.mockito.Mockito.verify;
10 import static org.mockito.Mockito.when;
11 
12 import org.junit.Test;
13 import org.mockito.Mock;
14 import org.mockito.Mockito;
15 import org.mockito.exceptions.misusing.InvalidUseOfMatchersException;
16 import org.mockito.exceptions.misusing.UnfinishedStubbingException;
17 import org.mockito.exceptions.misusing.UnfinishedVerificationException;
18 import org.mockitousage.IMethods;
19 import org.mockitoutil.TestBase;
20 
21 public class ExplicitFrameworkValidationTest extends TestBase {
22 
23     @Mock IMethods mock;
24 
25     @SuppressWarnings({"MockitoUsage", "CheckReturnValue"})
26     @Test
shouldValidateExplicitly()27     public void shouldValidateExplicitly() {
28         verify(mock);
29         try {
30             Mockito.validateMockitoUsage();
31             fail();
32         } catch (UnfinishedVerificationException e) {
33         }
34     }
35 
36     @SuppressWarnings({"MockitoUsage", "CheckReturnValue"})
37     @Test
shouldDetectUnfinishedStubbing()38     public void shouldDetectUnfinishedStubbing() {
39         when(mock.simpleMethod());
40         try {
41             Mockito.validateMockitoUsage();
42             fail();
43         } catch (UnfinishedStubbingException e) {
44         }
45     }
46 
47     @Test
shouldDetectMisplacedArgumentMatcher()48     public void shouldDetectMisplacedArgumentMatcher() {
49         Object ignored = any();
50         try {
51             Mockito.validateMockitoUsage();
52             fail();
53         } catch (InvalidUseOfMatchersException e) {
54         }
55     }
56 }
57