I have a method which doesn’t return a value. It instead accepts a list and modifies the members of this list. Obviously the list itself is mutable, as are its members.
EG: I want to mock this:
void modifyRequests(List<MutableObject> requests);
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Well, various mocking frameworks do provide ways of doing this (executing custom actions which use the parameters when a method is invoked) – but I would strongly consider not using mocking. Unless you really want to validate the protocol between your class-under-test and its collaborators, you should consider writing a fake instead of a mock. Then you can make the fake behave however you like – and typically (IME) you end up with simpler test code.
It’s not always appropriate, and mocking certainly has its place – but over time I’ve found that a well-written fake can be worth its weight in gold, particularly if it’s a dependency used by many classes.