Home | History | Annotate | Download | only in spies
      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 {
     19         public int len(String text) {
     20             return text.length();
     21         }
     22 
     23         public int size(Map<?, ?> map) {
     24             return map.size();
     25         }
     26 
     27         public int size(Collection<?> collection) {
     28             return collection.size();
     29         }
     30     }
     31 
     32     @Test
     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