Mockito: Trying to spy on method is calling the original method
Let me quote the official documentation: Important gotcha on spying real objects! Sometimes it’s impossible to use when(Object) for stubbing spies. Example: List list = new LinkedList(); List spy = spy(list); // Impossible: real method is called so spy.get(0) throws IndexOutOfBoundsException (the list is yet empty) when(spy.get(0)).thenReturn(“foo”); // You have to use doReturn() for stubbing … Read more