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.Mock; 9 import org.mockito.exceptions.misusing.MissingMethodInvocationException; 10 import org.mockito.exceptions.misusing.UnfinishedVerificationException; 11 import org.mockitoutil.TestBase; 12 13 import static org.junit.Assert.fail; 14 import static org.junit.Assume.assumeTrue; 15 import static org.mockito.Mockito.*; 16 17 public class DetectingFinalMethodsTest extends TestBase { 18 19 class WithFinal { foo()20 final int foo() { 21 return 0; 22 } 23 } 24 25 @Mock private WithFinal withFinal; 26 27 @Test shouldFailWithUnfinishedVerification()28 public void shouldFailWithUnfinishedVerification() { 29 assumeTrue("Does not apply for inline mocks", withFinal.getClass() != WithFinal.class); 30 verify(withFinal).foo(); 31 try { 32 verify(withFinal).foo(); 33 fail(); 34 } catch (UnfinishedVerificationException e) {} 35 } 36 37 @Test shouldFailWithUnfinishedStubbing()38 public void shouldFailWithUnfinishedStubbing() { 39 assumeTrue("Does not apply for inline mocks", withFinal.getClass() != WithFinal.class); 40 withFinal = mock(WithFinal.class); 41 try { 42 when(withFinal.foo()).thenReturn(null); 43 fail(); 44 } catch (MissingMethodInvocationException e) {} 45 } 46 } 47