我试图模拟一个void方法,每次都抛出异常。该方法以List<SomeClass>
为参数。如何将其传递给Mockito.any()
?
Mockito.doThrow(new Exception())
.when(myClassInstanceSpy)
.myVoidMethod(Mockito.any(List<SomeClass>.class)); // This fails!
这是我的班级定义:
class MyClass {
...
public void myVoidMethod(List<SomeClass> scList) {
// ...
}
}
答案 0 :(得分:4)
尝试:
Mockito.doThrow(new Exception())
.when(myClassInstanceSpy)
.myVoidMethod(Mockito.anyListOf(SomeClass.class));