vendredi 24 juillet 2020

Can Mockito mock a method without specifying each argument matcher individually?

Let's say I have some method with 5 arguments, like

public int foo(int arg1, int arg2, int arg3, int arg4, int arg5) {
  //do something
}

When I mock it, I end up doing something to the effect of

Mockito.when(myClass.foo(anyInt(), anyInt(), anyInt(), anyInt(), anyInt())).thenReturn(expectedResult);
//do stuff
Mockito.verify(myClass).foo(expectedArg1, expectedArg2, expectedArg3, expectedArg4, expectedArg5);

Is there a way of combining all the anyInt() matchers into something that's easier on the eyes? Something like Collections.nCopies(5, anyInt());

Aucun commentaire:

Enregistrer un commentaire