1
我想嘲笑javax.servlet.http.HttpServletRequest, getParameterNames()的回報。因此:Mockito可以處理在Scala中返回泛型的方法嗎?
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
難道我做錯了什麼?
似乎是一個Mockito錯誤,因爲getParameterNames肯定返回一個Enumeration [String]。但是這有助於我解決這個問題。謝謝! – gladed 2011-05-27 15:15:42