How to properly match varargs in Mockito

Posted by qualidafial on Stack Overflow See other posts from Stack Overflow or by qualidafial
Published on 2010-04-13T17:08:49Z Indexed on 2010/04/13 17:13 UTC
Read the original article Hit count: 573

Filed under:
|
|
|

I've been trying to get to mock a method with vararg parameters using Mockito:

interface A {
  B b(int x, int y, C... c);
}

A a = mock(A.class);
B b = mock(B.class);

when(a.b(anyInt(), anyInt(), any(C[].class))).thenReturn(b);
assertEquals(b, a.b(1, 2));

This doesn't work, however if I do this instead:

when(a.b(anyInt(), anyInt())).thenReturn(b);
assertEquals(b, a.b(1, 2));

This works, despite that I have completely omitted the varargs argument when stubbing the method.

Any clues?

© Stack Overflow or respective owner

Related posts about java

Related posts about mocking