• 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.matchers;
6 
7 import static org.junit.Assert.assertEquals;
8 import static org.mockito.ArgumentMatchers.*;
9 import static org.mockito.Mockito.when;
10 
11 import org.junit.Before;
12 import org.junit.Test;
13 import org.mockito.Mockito;
14 import org.mockitousage.IMethods;
15 import org.mockitoutil.TestBase;
16 
17 @SuppressWarnings("unchecked")
18 public class AnyXMatchersAcceptNullsTest extends TestBase {
19 
20     private IMethods mock;
21 
22     @Before
setUp()23     public void setUp() {
24         mock = Mockito.mock(IMethods.class);
25     }
26 
27     @Test
shouldAcceptNullsInAnyMatcher()28     public void shouldAcceptNullsInAnyMatcher() {
29         when(mock.oneArg((Object) any())).thenReturn("matched");
30 
31         assertEquals(null, mock.forObject(null));
32     }
33 
34     @Test
shouldNotAcceptNullInAllAnyPrimitiveWrapperMatchers()35     public void shouldNotAcceptNullInAllAnyPrimitiveWrapperMatchers() {
36         when(mock.forInteger(anyInt())).thenReturn("0");
37         when(mock.forCharacter(anyChar())).thenReturn("1");
38         when(mock.forShort(anyShort())).thenReturn("2");
39         when(mock.forByte(anyByte())).thenReturn("3");
40         when(mock.forBoolean(anyBoolean())).thenReturn("4");
41         when(mock.forLong(anyLong())).thenReturn("5");
42         when(mock.forFloat(anyFloat())).thenReturn("6");
43         when(mock.forDouble(anyDouble())).thenReturn("7");
44 
45         assertEquals(null, mock.forInteger(null));
46         assertEquals(null, mock.forCharacter(null));
47         assertEquals(null, mock.forShort(null));
48         assertEquals(null, mock.forByte(null));
49         assertEquals(null, mock.forBoolean(null));
50         assertEquals(null, mock.forLong(null));
51         assertEquals(null, mock.forFloat(null));
52         assertEquals(null, mock.forDouble(null));
53     }
54 }
55