Mockito 可以处理 Scala 中返回泛型的方法吗?
我想模拟 javax. servlet.http.HttpServletRequest,getParameterNames()。因此:
import org.specs.Specification
import org.specs.mock.Mockito
import scala.collection.JavaConversions._
import javax.servlet.http.HttpServletRequest
object SomethingSpec extends Specification with Mockito {
"Something" should {
"do something" in {
val request = mock[HttpServletRequest]
// This is fine
val elements: java.util.Enumeration[String] = List("p1", "p2").iterator
// But this bombs
request.getParameterNames() return elements
}
}
}
最后一行的编译会导致这个难以理解的错误:
found : java.util.Enumeration[String]
required: java.util.Enumeration[?0] where type ?0
我做错了什么吗?
I want to mock the return from javax.servlet.http.HttpServletRequest, getParameterNames(). Therefore:
import org.specs.Specification
import org.specs.mock.Mockito
import scala.collection.JavaConversions._
import javax.servlet.http.HttpServletRequest
object SomethingSpec extends Specification with Mockito {
"Something" should {
"do something" in {
val request = mock[HttpServletRequest]
// This is fine
val elements: java.util.Enumeration[String] = List("p1", "p2").iterator
// But this bombs
request.getParameterNames() return elements
}
}
}
Compilation of the last line results in this difficult-to-understand error:
found : java.util.Enumeration[String]
required: java.util.Enumeration[?0] where type ?0
Am I doing something wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试过从 HttpServletRequest 中转换返回值
,就像 getParameterNames 返回一个无类型枚举一样。
have you tried to cast the return value from the HttpServletRequest like
It seems, getParameterNames returns an untyped Enumeration.