![](/img/trans.png)
[英]How to verify invocations of the same mock method with the same argument that changes state between invocations in mockito?
[英]How to mock and verify method with argument T
我有一个方法:
public V doSomething(T t, Class<V> classV){}
我该如何使用模拟对象调用此方法并进行验证?
我正在尝试这样:
when(mockObject.doSomething(any(MyConcreteT.class), AnotherConcrete.class).
thenReturn(obj);
verify(mockObject).doSomething(any(MyConcreteT.class), AnotherConcrete.class);
但收到一个错误
InvalidUseOfMatchersException:参数匹配器的无效使用!
感谢任何帮助
AFAIK,Mockito要求所有参数都是非匹配项,或者所有参数都是匹配项。 不允许混合它们。 (不过,详细的错误消息应该告诉您这一点。)
尝试:
when(mySpy.doSomething(any(MyConcreteT.class), eq(AnotherConcrete.class)).
thenReturn(obj);
verify(mySpy).doSomething(any(MyConcreteT.class), eq(AnotherConcrete.class));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.