Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 139075
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T07:22:13+00:00 2026-05-11T07:22:13+00:00

This might seem like a pretty detailed question about Easymock, but I’m having a

  • 0

This might seem like a pretty detailed question about Easymock, but I’m having a hard time finding a support site/forum/mailing list for this library.

I’m encountering a bug when using the captures() method that seems to return the captured parameters out of order.

Here’s a simplified version of what I am testing:

public class CaptureTest extends TestCase {      // interface we will be mocking     interface Processor {             void process(String x);     }      // class that uses the interface above which will receive the mock     class Component {          private Processor processor;          private String[] s = { 'one', 'two', 'three', 'four' };          Component(Processor processor) {             this.processor = processor;         }          public void doSomething() {             for (int i = 0; i < s.length; i++) {                 processor.process(s[i]);             }         } }      public void testCapture() {          //create the mock, wire it up             Processor mockProcessor = createMock(Processor.class);         Component component = new Component(mockProcessor);          //we're going to call the process method four times         //with different arguments, and we want to capture          //the value passed to the mock so we can assert against it later             Capture<String> cap1 = new Capture<String>();         Capture<String> cap2 = new Capture<String>();         Capture<String> cap3 = new Capture<String>();         Capture<String> cap4 = new Capture<String>();          mockProcessor.process(and(isA(String.class), capture(cap1)));         mockProcessor.process(and(isA(String.class), capture(cap2)));         mockProcessor.process(and(isA(String.class), capture(cap3)));         mockProcessor.process(and(isA(String.class), capture(cap4)));          replay(mockProcessor);          component.doSomething();          //check what values were passed to the mock         assertEquals('one', cap1.getValue());         assertEquals('two', cap2.getValue());         assertEquals('three', cap3.getValue());         assertEquals('four', cap4.getValue());          verify(mockProcessor);     }  } 

(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 case the arguments are complex objects with a handful of fields, and 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).

When I run the test, it fails at:

junit.framework.ComparisonFailure: expected:<[one]> but was:<[four]>

Meaning that the parameter that EasyMock is capturing in cap1 is not the first call to the method, but the last (since the value is four). I get the same results if I reverse the captures() declarations, i.e. use cap4 with the first method call, etc.

This seems like it might be a bug within EasyMock – different parameters passed to the same method in different invocations don’t seem to be capture correctly.

Is anyone else using capture() with EasyMock and having similar problems? Is there an easy workaround you know of, or a different way I can capture the parameters being passed to my mock’s methods?

Update 1: fixed code sample to show I am using createMock, not createStrictMock, but I get the same error with both (although the actual value of what is captured changes).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T07:22:14+00:00Added an answer on May 11, 2026 at 7:22 am

    I’ve received an answer on the bug I submitted to the Easymock sourceforge site, and a developer has confirmed it is indeed a bug with this version of Easymock.

    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);   } } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 76k
  • Answers 76k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Thank you very much, Kent! Here is the solution for… May 11, 2026 at 3:04 pm
  • added an answer If the class is only a wrapper around the function… May 11, 2026 at 3:04 pm
  • added an answer No it isn't possible. IFilters are mapped to a document… May 11, 2026 at 3:04 pm

Related Questions

This might seem like a pretty detailed question about Easymock, but I'm having a
What's your standard way of debugging a problem? This might seem like a pretty
Win32's CreateFile has FILE_FLAG_DELETE_ON_CLOSE , but I'm on Linux. I want to open a
Background: I have a little video playing app with a UI inspired by the
Oh, 2 things: 1) It is a console application. 2 ) I know it

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.