Argument Captor for varargs

2,203 views
Skip to first unread message

David Wallace

unread,
Mar 11, 2012, 8:29:38 PM3/11/12
to mockito
Can anybody suggest a good way of making an ArgumentCaptor for a
varargs argument? For example, if I make a mock myMock of a class
that has a method
process( Foo... foos )

I'd like to be able to write something like this.
ArgumentCaptor<Foo[].class> captor =
ArgumentCaptor.forClass( Foo[].class );
verify( myMock ).process( captor.capture());

and have this successfully verify a call like myMock.process( foo1,
foo2, foo3 );

The above doesn't work, because Mockito doesn't see process( foo1,
foo2, foo3 ) as a match for process( some array of Foo ).

Does anybody know a good workaround to this? If not, I shall probably
request this as a new feature.

Brice Dutheil

unread,
Mar 11, 2012, 9:31:14 PM3/11/12
to moc...@googlegroups.com
I don't think this is possible with the current ArgumentCaptor.
In order to work I think it needs to update a captureVararg, just like we have anyVararg.

Feel free to add an enhancement issue.

-- Brice




--
You received this message because you are subscribed to the Google Groups "mockito" group.
To post to this group, send email to moc...@googlegroups.com.
To unsubscribe from this group, send email to mockito+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mockito?hl=en.


Brice Dutheil

unread,
Aug 30, 2012, 6:53:39 PM8/30/12
to moc...@googlegroups.com
Nope it needs to be implemented.

Cheers,
-- Brice



On Thu, Aug 30, 2012 at 11:46 PM, Joshua Chaitin-Pollak <pard...@gmail.com> wrote:
Hi,

I know its been a few months, but has this been implemented? I looked through the issues on the Mockito site and couldn't find anything relevant.

This feature would be helpful to me... can anyone suggest a workaround?

Thanks,

Josh
To view this discussion on the web visit https://groups.google.com/d/msg/mockito/-/OPrr9NbpInoJ.

Szczepan Faber

unread,
Sep 18, 2012, 5:46:06 PM9/18/12
to moc...@googlegroups.com
You can subscribe to this issue for updates:
http://code.google.com/p/mockito/issues/detail?id=372

Also if someone wants take a stab at implementation, we would happily merge it.

Cheers!
Szczepan Faber
Principal engineer@gradleware
Lead@mockito
Reply all
Reply to author
Forward
0 new messages