18

使用 JMock:

context.checking(new Expectations() {{
    // Other oneOf() will() statements ...

    oneOf(shopAccount).enter(100, with(any(String.class)));
    will(returnValue(true));

   // Other oneOf() will() statements ...
}});

执行期间将引发以下异常:

java.lang.IllegalArgumentException:并非所有参数都被明确匹配:要么所有参数都必须由匹配器指定,要么所有参数都必须由值指定,你不能混合匹配器和值。

为什么我不能这样做?使用with(any(Klass.class))

4

1 回答 1

21

如果with对任何参数使用子句,则必须对所有参数使用它们,尝试

oneOf(shopAccount).enter( with(equalTo(100)) , with(any(String.class)));

于 2011-04-23T17:25:08.907 回答