• 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.junit.Assume.assumeTrue;
9 import static org.mockito.Mockito.*;
10 
11 import org.junit.Test;
12 import org.mockito.Mock;
13 import org.mockito.exceptions.misusing.MissingMethodInvocationException;
14 import org.mockito.exceptions.misusing.UnfinishedVerificationException;
15 import org.mockitoutil.TestBase;
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 
38     @Test
shouldFailWithUnfinishedStubbing()39     public void shouldFailWithUnfinishedStubbing() {
40         assumeTrue("Does not apply for inline mocks", withFinal.getClass() != WithFinal.class);
41         withFinal = mock(WithFinal.class);
42         try {
43             when(withFinal.foo()).thenReturn(null);
44             fail();
45         } catch (MissingMethodInvocationException e) {
46         }
47     }
48 }
49