• 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.bugs;
6 
7 import org.junit.After;
8 import org.junit.Test;
9 import org.mockito.Mock;
10 import org.mockitousage.IMethods;
11 import org.mockitoutil.TestBase;
12 
13 import static org.mockito.Matchers.*;
14 import static org.mockito.Mockito.never;
15 import static org.mockito.Mockito.verify;
16 
17 public class NPEWithCertainMatchersTest extends TestBase {
18 
19     @Mock IMethods mock;
20 
21     @After
clearState()22     public void clearState() {
23         this.resetState();
24     }
25 
26     @Test
shouldNotThrowNPEWhenIntegerPassed()27     public void shouldNotThrowNPEWhenIntegerPassed() {
28         mock.intArgumentMethod(100);
29 
30         verify(mock).intArgumentMethod(isA(Integer.class));
31     }
32 
33     @Test
shouldNotThrowNPEWhenIntPassed()34     public void shouldNotThrowNPEWhenIntPassed() {
35         mock.intArgumentMethod(100);
36 
37         verify(mock).intArgumentMethod(isA(Integer.class));
38     }
39 
40     @Test
shouldNotThrowNPEWhenIntegerPassedToEq()41     public void shouldNotThrowNPEWhenIntegerPassedToEq() {
42         mock.intArgumentMethod(100);
43 
44         verify(mock).intArgumentMethod(eq(new Integer(100)));
45     }
46 
47     @Test
shouldNotThrowNPEWhenIntegerPassedToSame()48     public void shouldNotThrowNPEWhenIntegerPassedToSame() {
49         mock.intArgumentMethod(100);
50 
51         verify(mock, never()).intArgumentMethod(same(new Integer(100)));
52     }
53 
54     @Test(expected = AssertionError.class)
shouldNotThrowNPEWhenNullPassedToEq()55     public void shouldNotThrowNPEWhenNullPassedToEq() {
56         mock.objectArgMethod("not null");
57 
58         verify(mock).objectArgMethod(eq(null));
59     }
60 
61     @Test(expected = AssertionError.class)
shouldNotThrowNPEWhenNullPassedToSame()62     public void shouldNotThrowNPEWhenNullPassedToSame() {
63         mock.objectArgMethod("not null");
64 
65         verify(mock).objectArgMethod(same(null));
66     }
67 }
68