1

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?

0

1 Answer 1

1

have you tried to cast the return value from the HttpServletRequest like

request.getParameterNames().asInstanceOf[java.util.Enumeration[String]] returns elements

It seems, getParameterNames returns an untyped Enumeration.

Sign up to request clarification or add additional context in comments.

1 Comment

Seems like a Mockito bug, since getParameterNames definitely returns an Enumeration[String]. But this helps me work around the problem. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.