• 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 
6 package org.mockitousage.misuse;
7 
8 import org.junit.Test;
9 import org.mockito.Mock;
10 import org.mockito.Mockito;
11 import org.mockito.exceptions.misusing.InvalidUseOfMatchersException;
12 import org.mockito.exceptions.misusing.UnfinishedStubbingException;
13 import org.mockito.exceptions.misusing.UnfinishedVerificationException;
14 import org.mockitousage.IMethods;
15 import org.mockitoutil.TestBase;
16 
17 import static org.junit.Assert.fail;
18 import static org.mockito.Matchers.anyObject;
19 import static org.mockito.Mockito.verify;
20 import static org.mockito.Mockito.when;
21 
22 public class ExplicitFrameworkValidationTest extends TestBase {
23 
24     @Mock IMethods mock;
25 
26     @Test
shouldValidateExplicitly()27     public void shouldValidateExplicitly() {
28         verify(mock);
29         try {
30             Mockito.validateMockitoUsage();
31             fail();
32         } catch (UnfinishedVerificationException e) {}
33     }
34 
35     @Test
shouldDetectUnfinishedStubbing()36     public void shouldDetectUnfinishedStubbing() {
37         when(mock.simpleMethod());
38         try {
39             Mockito.validateMockitoUsage();
40             fail();
41         } catch (UnfinishedStubbingException e) {}
42     }
43 
44     @Test
shouldDetectMisplacedArgumentMatcher()45     public void shouldDetectMisplacedArgumentMatcher() {
46         anyObject();
47         try {
48             Mockito.validateMockitoUsage();
49             fail();
50         } catch (InvalidUseOfMatchersException e) {}
51     }
52 }
53