我是 Groovy 的新手(同样也是 JMock 的新手),并且在构建对被模拟方法的参数使用匹配器的期望时遇到了一些麻烦。当我尝试做这样的事情时:
Expectations e = new Expectations();
e.allowing(mockObject).doSomething(Expectations.with(aNonNull(ImmutableCollection.class)))
e.will(returnValue(someResponse))
在构建期望时会导致以下错误:
groovy.lang.MissingMethodException: No signature of method: static org.jmock.Expectations.with() is applicable for argument types: (org.hamcrest.core.IsNot) values: [not null]
Possible solutions: with(boolean), with(org.hamcrest.Matcher), with(byte), with(org.hamcrest.Matcher), with(char), with(org.hamcrest.Matcher)
aNonNull 返回Matcher<T>
(org.hamcrest.core.IsNot implements Matcher<T>
) 并且有一个 Expectations.with 方法接受一个 Matcher 所以我不知道为什么 Groovy 试图找到一个带有具体类而不是指定接口的版本由非空。我还尝试将 aNonNull 的返回值转换为 Matcher 并且Matcher<T>
不对错误进行任何更改。我不确定泛型是否有一些东西让 Groovy 感到困惑,或者还有什么要检查的。