Mock Object is object that mimic/copy some real object behavior in a controlled way. It is implemented by some well known object interfaces with their dummy functionality. It is created to test the behavior of other object. It originally became popular by the junit team and the expert programmers/developers. The mock object simulate the behavior of real, complex object in unit testing.
Mock is provided by the J2EE for each key interface on server side of j2ee specification. For example -
DelegatingServletInputStream- This object is used for the mock implementation of the ServletInputStream interface.
DelegatingServletOutputStream- This object is used for the mock implementation of the ServletOutputStream interface. Whenever required to check the content written by the output stream it can be used.
MockHttpServletRequest- This interface can be used for mock implementation of the HttpServletRequest interface. HttpServletRequest interface is commonly used in the application.
MockHttpServletResponse - It is used for the mock implementation of the HttpServletResponse interface.
MockHttpSession - This interface can be used for the mock implementation of the HttpServletSession interface.
The http request parameters holds very important value, which drive the main functionality of web components. The MockHttpServletRequest allows to set these parameter. For Example-
MockHttpServletRequest request= new MockHttpServletRequest("GET", "index.html"); request.addParameter("Name", "James"); request.addParameter("ID", "007");