Jack Edmonds
Jack Edmonds

Reputation: 33171

Mockito Disregard Parameters

Is there a way to get a mocked class to return some object no matter what arguments the function is called with?

For example, if one of my parameters' types did not have the .equals() method properly implemented.

Upvotes: 9

Views: 3084

Answers (2)

Yoztastic
Yoztastic

Reputation: 862

There are also generics i.e.

when(mock.someMethod(Matchers.<String>any(), Matchers.<Interval>any(), Matchers.Integer>any())).thenReturn(yourValue);

Upvotes: 3

drekka
drekka

Reputation: 21883

when(mock.someMethod(any()).thenReturn(yourValue);

The any() matcher basically says you can have any value or a null. Check out the documentation at mockito, especially the section on Argument Matchers.

Upvotes: 14

Related Questions