Menu

#26 Collecting parameter design pattern

EasyMock_2.5
open
EasyMock (33)
5
2012-10-05
2009-06-25
No

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

Discussion

  • Henri Tremblay

    Henri Tremblay - 2009-08-18

    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.

     
  • Ragnvald Barth

    Ragnvald Barth - 2009-08-19

    public class CollectingMatcher<T> implements IArgumentMatcher

     
  • Ragnvald Barth

    Ragnvald Barth - 2009-08-19

    Generic collector interface

     
  • Ragnvald Barth

    Ragnvald Barth - 2009-08-19

    junit test

     
  • Ragnvald Barth

    Ragnvald Barth - 2009-08-19

    Stupid example code that cannot be tested without an argument matcher like this one.

     
  • Ragnvald Barth

    Ragnvald Barth - 2009-08-19

    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!

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.