开发者

Mockito Disregard Parameters

开发者 https://www.devze.com 2023-03-14 18:06 出处:网络
Is there a way to get a mocked class to return some object no matter what arguments the function is called with?

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 param开发者_Python百科eters' types did not have the .equals() method properly implemented.


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.


There are also generics i.e.

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

精彩评论

暂无评论...
验证码 换一张
取 消