Bick
Bick

Reputation: 18511

Mockito - How do I mock a method that recieves param - (Object... o)

How do I mock a method that receives param - (Object... o)?
for instance I have the following method

Obj getByIds(String... ids);

I want something like

doReturn(...).when(myProxy).getByIds(any(String[].class));

or

doReturn(...).when(myProxy).getByIds(any(String.class));

But they both fail.

Upvotes: 1

Views: 78

Answers (2)

Toon Borgers
Toon Borgers

Reputation: 3658

doReturn(...).when(myProxy).getByIds(Matchers.<String>anyVararg())

should work, see here

Upvotes: 2

user1717259
user1717259

Reputation: 2863

Try doReturn(...).when(myProxy).getByIds((String) anyVarargs())

Upvotes: 0

Related Questions