【发布时间】:2011-06-22 01:02:54
【问题描述】:
有没有办法让一个模拟类返回一些对象,无论函数调用的参数是什么?
例如,如果我的参数类型之一没有正确实现 .equals() 方法。
【问题讨论】:
有没有办法让一个模拟类返回一些对象,无论函数调用的参数是什么?
例如,如果我的参数类型之一没有正确实现 .equals() 方法。
【问题讨论】:
when(mock.someMethod(any()).thenReturn(yourValue);
any() 匹配器基本上说你可以有任何值或空值。查看 mockito 的 documentation,尤其是 Argument Matchers 部分。
【讨论】:
还有泛型,即
when(mock.someMethod(Matchers.<String>any(), Matchers.<Interval>any(), Matchers.Integer>any())).thenReturn(yourValue);
【讨论】: