• 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.spies;
6 
7 import org.junit.Test;
8 import org.mockitoutil.TestBase;
9 
10 import java.util.Collection;
11 import java.util.Map;
12 
13 import static org.mockito.Matchers.*;
14 import static org.mockito.Mockito.spy;
15 
16 public class StubbingSpiesDoesNotYieldNPETest extends TestBase {
17 
18     class Foo {
len(String text)19         public int len(String text) {
20             return text.length();
21         }
22 
size(Map<?, ?> map)23         public int size(Map<?, ?> map) {
24             return map.size();
25         }
26 
size(Collection<?> collection)27         public int size(Collection<?> collection) {
28             return collection.size();
29         }
30     }
31 
32     @Test
shouldNotThrowNPE()33     public void shouldNotThrowNPE() throws Exception {
34         Foo foo = new Foo();
35         Foo spy = spy(foo);
36 
37         spy.len(anyString());
38         spy.size(anyMap());
39         spy.size(anyList());
40         spy.size(anyCollection());
41         spy.size(anySet());
42     }
43 }
44