Mocking request http



Recently I needed to simulate some requests http so then I used EasyMock. Quite useful indeed and very simple:


HelloServletMock mock = new HelloServletMock();

HttpServletRequest request = createMock(HttpServletRequest.class);
HttpServletResponse response = createMock(HttpServletResponse.class);

expect(request.getParameter(“yourName“)).andReturn(“Jose Carlos“).times(1, 2);

On this case the request will return “Jose Carlos” when I get the paramter “yourName”, example:

String yourName = request.getParameter(“yourName”);

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s