Mockito 1.5 has been released with several nice enhancements. Perhaps one of the most useful is the ability to spy on non-mock objects. In other words, you can verify that methods are called on the non-mock object. So, for example (from the release notes):
List list = new LinkedList(); List spy = spy(list); //wow, I can stub it! stub(spy.size()).toReturn(100); //wow, I can use it and add real elements to the list! spy.add("one"); //wow, I can verify it! verify(spy).add("one);
I haven’t wanted to do this too often, but there was an occasion or two.
Another improvement is supposed to result in more readable code. Instead of
it is now possible to write:
Notice that the code is exactly the same length, so it’s clearly up to you whether you think it’s more or less readable. In addition to
doReturn(), there’s also
Check out the Mockito documentation for examples and details on how to use.