【发布时间】:2010-07-08 22:03:10
【问题描述】:
已解决。 IntelliJ 没有强调我的导入不完整这一事实。
嗨,
我有一个简单的 Scala 程序,我正在尝试使用 jMock 进行开发。设置基本期望效果很好,但出于某种原因,Scala 不理解我从模拟对象返回值的尝试。我的 maven 构建喷出以下错误
TestLocalCollector.scala:45: error: not found: value returnValue
one (nodeCtx).getParameter("FilenameRegex"); will( returnValue(regex))
^
而各自的代码sn-ps是
@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?我在这里错过了什么?
【问题讨论】:
-
你能在评论中留下你最终使用的正确语法吗?我将在下面的答案中包含它。
-
这里是相关部分,
returnValue静态方法不可见,因此出现错误。而will方法只记录最新模拟操作的动作,这就是为什么它可以在下一行或分号之后:) import org.jmock.Expectations import org.jmock.Expectations._ ... context。检查(新期望 {{ oneOf (nodeCtx).getParameter("FilenameRegex") will( returnValue(".*\\.data") ) }}) -
谢谢。然后是范围问题。使用正确的导入,它会更好地工作。答案已更新。