Mimic an HTTPRequest and HTTPResponse object in Java
- by Ankur
How do I mimic an HTTPServletRequest and HTTPServletResponse object. The reason is I want to test the behaviour of some servlets.
I know JUnit probably provides this functionality but I don't know how to use it (I will learn soon) and need to do this reasonably quickly.
HTTPServletRequest and HTTPServletResponse are both interfaces so they can't be instantiated. There is a HttpServletRequestWrapper which implements HttpServletRequest but it doesn't seem to have any setParameter() type methods and HttpServletResponse doesn't seem to have any implementing classes at all.
How can I test my code by passing a suitable HttpServletRequest object and then checking that the received HttpServletResponse object matches what I expect?