Menu

#16 Possible bug with captures()

EasyMock_2.5
closed
EasyMock (40)
5
2012-10-05
2009-02-19
Matt Brown
No

I think I may have run into a possible bug with using captures() to capture a parameter passed to a mocked method.

I've attached a (very simplified) test case to prove the behavior.

Please note that this is just a simplified test case - I know that I could specify the exact value of the arguments I expect passed to my mock, but in my real code the arguments are complex objects with a number of fields, and in the unit test (of the class using the mocked component), I want to capture the object so I can assert against just a few of those fields without re-creating the entire object in my test case.

Can someone please confirm if this is indeed a bug or if I am simply using this method wrong?

Thanks
Matt Brown
octavius@gmail.com

Discussion

  • Matt Brown

    Matt Brown - 2009-02-19

    test case

     
  • Henri Tremblay

    Henri Tremblay - 2009-02-19

    It is indeed a bug. The capture is done even if it was already done. The current workaround is to implement your own capture object and override setValue to do this:

    @Override
    public void setValue(T value) {
    if(!hasCaptured()) {
    super.setValue(value);
    }
    }

     
  • Matt Brown

    Matt Brown - 2009-02-24

    Thanks Henri - that workaround seems to do the trick.

     

Log in to post a comment.