【发布时间】:2010-11-30 21:20:51
【问题描述】:
我是 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 实现Matcher<T>)并且有一个 Expectations.with 方法需要一个 Matcher 所以我不确定为什么 Groovy 试图找到一个版本采用具体类而不是由 aNonNull 指定的接口。我还尝试将 aNonNull 的返回值转换为 Matcher 和 Matcher<T> ,而错误没有任何变化。我不确定泛型是否有一些东西让 Groovy 感到困惑,或者还有什么需要检查的。
【问题讨论】:
-
涉及利基技术。因此,不太可能找到具有 déjà vu 经验的人。但是,如果您可以将问题分解为最新的、可重现的测试用例,我相信问题可以得到解决(如果没有解决)。
标签: java groovy jmock hamcrest