varargs param matching

350 views
Skip to first unread message

Kevin Wong

unread,
Jan 21, 2009, 4:38:55 PM1/21/09
to mockito
I'm having a problem stubbing a method with varargs.

This results in an error message "1 matchers expected, 2 recorded":

when(clientDesk.shipFile(anyString(),
eq(new NewShipmentForm[] {form1, form2, form3})))
.thenReturn(Arrays.asList(shipmentId1, shipmentId2, shipmentId3));

This doesn't match any method calls, so shipFile(..) returns an empty
List:

when(clientDesk.shipFile((String) notNull(),
(NewShipmentForm) anyObject()))
.thenReturn(Arrays.asList(shipmentId1, shipmentId2,
shipmentId3));

What is the proper way to match a vararg param?

szczepiq

unread,
Jan 21, 2009, 5:54:00 PM1/21/09
to moc...@googlegroups.com
Hi,

Try:

when(clientDesk.shipFile(anyString(),
eq(form1), eq(form2), eq(form3)))
.thenReturn(Arrays.asList(shipmentId1,
shipmentId2, shipmentId3));

Cheers,
Szczepan Faber

Kevin Wong

unread,
Feb 11, 2009, 10:59:52 PM2/11/09
to mockito
Yep...diddna think of that. It works. Thanks.

On Jan 21, 5:54 pm, szczepiq <szcze...@gmail.com> wrote:
> Hi,
>
> Try:
>
>        when(clientDesk.shipFile(anyString(),
>                        eq(form1), eq(form2), eq(form3)))
>                        .thenReturn(Arrays.asList(shipmentId1,
> shipmentId2, shipmentId3));
>
> Cheers,
> Szczepan Faber
>
Reply all
Reply to author
Forward
0 new messages