解决。 IntelliJ没有强调我的导入不完整的事实。
您好,
我有一个简单的Scala程序,我正在尝试使用jMock开发。设置基本期望很有效,但由于某种原因,Scala不理解我尝试从模拟对象返回值。我的maven构建出现了以下错误
TestLocalCollector.scala:45: error: not found: value returnValue
one (nodeCtx).getParameter("FilenameRegex"); will( returnValue(regex))
^
各个代码段
@Before def setUp() : Unit = { nodeCtx = context.mock(classOf[NodeContext]) }
...
// the value to be returned
val regex = ".*\\.data"
...
// setting the expectations
one (nodeCtx).getParameter("FilenameRegex"); will( returnValue(regex))
听起来我觉得Scala期望静态jMock方法returnValue
是val
?我在这里缺少什么?
答案 0 :(得分:2)
您确定';
'吗?
one (nodeCtx).getParameter("FilenameRegex") will( returnValue(regex))
可能会更好。
在this example中,您会看到如下行:
expect {
one(blogger).todayPosts will returnValue(List(Post("...")))
}
带有以下评论:
通过将“will”定义为Scala中缀运算符,指定返回值在同一表达式中的含义 在Java等价物中,我们必须进行单独的方法调用(我们最喜欢的IDE可能会坚持使用下一行!)
one(blogger).todayPosts; will(returnValue(List(Post("..."))))
^
|
-- semicolon only in the *Java* version
returnValue
静态方法不可见,因此错误 并且will
方法只记录对最新模拟操作的操作,这就是它可以在下一行或分号后的原因:)
import org.jmock.Expectations
import org.jmock.Expectations._
...
context.checking(
new Expectations {
{ oneOf (nodeCtx).getParameter("FilenameRegex") will( returnValue(".*\\.data") ) }
}
)