Collecting parameter design pattern
Brought to you by:
tammofreese
Scenario:
Your System Under Test (SUT) calls a method on a collaborator, sending in a List as a parameter.
The collaborator adds an element to the list before returning.
The SUT uses the list with the added element.
You need to mock the collaborator and test the SUT.
There is no argument matcher in EasyMock supporting a scenario like this, so I created one. Would it be interesting to include such a matcher in the list of predefined argument matchers for EasyMock?
Ragnvald
It sounds a little too specific to be a standard EasyMock matcher. However, can you attach it to this tracker item so I can have a look.
public class CollectingMatcher<T> implements IArgumentMatcher
Generic collector interface
junit test
Stupid example code that cannot be tested without an argument matcher like this one.
I attached the files "as is". I guess at least you would have to change the namespace if you decide to use them. The files in question are CollectingMatcher.java, Collector.java and CollectingParameterMatcherTest.java.
Is it to specific?
Consider that this matcher can be used in any setting where the SUT sends an object to a collaborator, and the collaborator modifies the object. I created a simple but stupid 30 lines example to illustrate this (see Sut.java). The point is that mocking the emailAddressGenerator and testing the createUser method can only be done by using an argument matcher like the one I created.
Hope you find it interesting!