You get a NPE because the second call to mFubar.getModel()
, just like the first, returns null
. You can't use recorded results inside an expectation recording block; these values are meant to be obtained from the code under test only.
Besides, it doesn't look like the Model
class is being mocked here, so trying to record a call to getAllDogs()
wouldn't work either. For that, you would need to declare a @Mocked Model model
mock field or mock parameter.
Finally, the default return value for a mocked method having a collection (List, Set, Map, etc.) as its return type already is an empty collection. So, writing result = new HashSet<Dog>();
would be redundant anyway.