Ok, I think I misunderstood the usage of the ArgumentCapture.
I thought the ArgumentCapture was able to record the state of whatever
object used as argument, no matter if new or pre-instantiated.
But then, my question is, how do I test that something like that:
Code:
myservice.doSomething("a");
myservice.doSomething("b");
myservice.doSomething("c");
Test:
Test that the method "doSomething" has been called 3 times with
arguments "a", "b", "c"
Is it only doable using custom ArgumentMatcher? Like in this revised
test case:
http://pastebin.com/2c3zF8sv
Luciano
On Jul 26, 12:08 pm, Max <
maxon...@gmail.com> wrote:
> This is not the Mockito behaviour but the behaviour of Java. In the context
> of the test or even any context, it does matter if the returned object is
> new or instantiated only once.
>
> If you change the same object three times before verifying values the object
> will have whatever last value you set. So
>
> assertEquals("John", captor.getAllValues().get(0).getName());
> assertEquals("Ben", captor.getAllValues().get(1).getName());
> assertEquals("Don", captor.getAllValues().get(2).getName());
>
> is the same as
>
> assertEquals("John", "Don");
> assertEquals("Ben", "Don");
> assertEquals("Don", "Don");
>
> If you want your test pass then do,
>
 >    1.                 Dummy d = mList.get(12);
>    2.                 d.setName("John");
>    3.                 d.setId(100);
>    4.                 mList.add(d);
>    5.                 assertEquals("John", captor.getAllValues().get(0).
>    getName());
>    6.
>    7.                 Dummy g = mList.get(10);
>    8.                 mList.get(12);
>    9.                 g.setName("Ben");
>    10.                 g.setId(200);
>    11.                 mList.add(g);
>    12.                 assertEquals("Ben", captor.getAllValues().get(1).
>    getName());
>    13.
>    14.                 Dummy x = mList.get(120);
>    15.                 x.setName("Don");
>    16.                 x.setId(300);
>    17.                 mList.add(x);
>    18.                 assertEquals("Don", captor.getAllValues().get(2).
>    getName());
> > > > <
mockito%2Bunsu...@googlegroups.com<mockito%252Bunsubscribe@googlegroup 
s.com>