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 @SuppressWarnings({"MockitoUsage", "CheckReturnValue"}) 27 @Test shouldValidateExplicitly()28 public void shouldValidateExplicitly() { 29 verify(mock); 30 try { 31 Mockito.validateMockitoUsage(); 32 fail(); 33 } catch (UnfinishedVerificationException e) {} 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 @Test shouldDetectMisplacedArgumentMatcher()47 public void shouldDetectMisplacedArgumentMatcher() { 48 anyObject(); 49 try { 50 Mockito.validateMockitoUsage(); 51 fail(); 52 } catch (InvalidUseOfMatchersException e) {} 53 } 54 } 55