Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I was playing around with your test and could not solve. However I extended the Capture Class to see if the values were set in a different order (I was suspicious that EasyMock internally was using a hash with a key generated from the methods and the parameters) I was wrong the methods are set in the correct order. But there is something really weird going on.. It seems that the algorithm does some kind assigning pattern.. Well let me show the code and the strange output.... BTW the changes from mock, niceMock and strictMock didn't make anydifference..</p> <pre><code>class MyCapture extends Capture&lt;String&gt; { private String id; public MyCapture(String id) { super(); System.out.printf("Constructor %s expecting %s\n", id, this.getClass().getName()); this.id = id; } private static final long serialVersionUID = 1540983654657997692L; @Override public void setValue(String value) { System.out.printf("setting value %s expecting %s \n", value, id); super.setValue(value); } @Override public String getValue() { System.out .printf("getting value %s expecting %s \n", super.getValue(), id); return super.getValue(); } } public void testCapture() { // create the mock, wire it up Processor mockProcessor = createStrictMock(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&lt;String&gt; cap1 = new MyCapture("A"); Capture&lt;String&gt; cap2 = new MyCapture("B"); Capture&lt;String&gt; cap3 = new MyCapture("C"); Capture&lt;String&gt; cap4 = new MyCapture("D"); 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("A", cap1.getValue()); assertEquals("B", cap2.getValue()); assertEquals("C", cap3.getValue()); assertEquals("D", cap4.getValue()); verify(mockProcessor); } </code></pre> <p>}</p> <p>*And this is the output *</p> <pre><code>Constructor A expecting com.comp.core.dao.impl.CaptureTest$MyCapture Constructor B expecting com.comp.core.dao.impl.CaptureTest$MyCapture Constructor C expecting com.comp.core.dao.impl.CaptureTest$MyCapture Constructor D expecting com.comp.core.dao.impl.CaptureTest$MyCapture calling process A setting value A expecting A calling process B setting value B expecting A &lt;&lt;Setting the wrong guy setting value B expecting A &lt;&lt;Setting the wrong guy setting value B expecting B &lt;&lt;Ops this is the right one..stop calling process C setting value C expecting B &lt;&lt;Setting the wrong guy setting value C expecting B &lt;&lt;Setting the wrong guy setting value C expecting C &lt;&lt;Setting the wrong guy calling process D setting value D expecting C &lt;&lt;Setting the wrong guy setting value D expecting C &lt;&lt;Setting the wrong guy setting value D expecting D &lt;&lt;Ops this is the right one..stop getting value B expecting A </code></pre> <p>Sorry I can't help you more. It might be indeed a bug in easy mock.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload