How to create HttpServletResponse for unit tests, where I can write output stream and headers(not MockHttpServletResponse)?
In assert block I expect to compare OutputStream and headers with etalon httpServletResponse.
I used Spring4, java8 and EasyMock lib.
Defines an HTTP servlet response that a servlet running on a Web server sends to a client using HTTP. This interface allows the servlet's service method to access HTTP headers and return data to its client. The servlet engine implements this interface.
The HttpServletResponse interface enables a servlet to formulate an HTTP response to a client. The response object encapsulates all information to be returned from the server to the client.
Below way by using EasyMock
 HttpServletRequest mockRequest = EasyMock.createMock(HttpServletRequest.class);
 HttpServletResponse mockResponse = EasyMock.createMock(HttpServletResponse.class);
Using spring mock class
import  org.springframework.mock.web.MockHttpServletResponse;
import  org.springframework.mock.web.MockHttpServletRequest;
HttpServletRequest httpServletRequest = new MockHttpServletRequest();
HttpServletResponse httpServletResponse = new MockHttpServletResponse();
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With