关于with(任何(Class.class)))与JMock [英] About with(any(Class.class))) with JMock
问题描述
使用JMock:
context.checking(new Expectations() {{
// Other oneOf() will() statements ...
oneOf(shopAccount).enter(100, with(any(String.class)));
will(returnValue(true));
// Other oneOf() will() statements ...
}});
执行期间将引发以下异常:
The following exception will be raised during execution:
java.lang.IllegalArgumentException:并非所有参数都被赋予显式匹配器:要么所有参数都必须由匹配器指定,要么所有参数都必须由值指定,您不能混合使用匹配器和值。
java.lang.IllegalArgumentException: not all parameters were given explicit matchers: either all parameters must be specified by matchers or all must be specified by values, you cannot mix matchers and values.
为什么我不能这样做?使用使用(任何(Klass.class))
?
Why i cannot do this way? using with(any(Klass.class))
?
推荐答案
如果你对任何参数使用和
子句,你必须对所有参数使用它们,试试
if you use a with
clause for any parameter, you must use them for all the parameters, try
oneOf(shopAccount).enter( with(equalTo(100)),with(any(String.class)));
oneOf(shopAccount).enter(with(equalTo(100)), with(any(String.class)));
这篇关于关于with(任何(Class.class)))与JMock的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!