Loading ...
Sorry, an error occurred while loading the content.

Re: [XP] Re: How to create HttpServletRequest?

Expand Messages
  • William Pietri
    ... Actually, building one s own mocks isn t that painful. If you take the interface and fill it in with a lot of throw new RuntimeException( unimplemented );
    Message 1 of 3 , Jan 3, 2003
      On Fri, 2003-01-03 at 09:31, Paul Hodgetts wrote:
      > Carfield Yim wrote:
      > > I would like to see if there anyway to create an instance of
      > > HttpServletRequest, so that I can write unit test of method that need
      > > create HttpServletRequest?
      > HttpServletRequest is an interface. Each specific container will
      > provide an implementation of it that is instantiated and passed
      > to your servlet. You will either need to find out what the
      > concrete implementation is for your container and how to build
      > one with all the necessary details [...]

      Actually, building one's own mocks isn't that painful. If you take the
      interface and fill it in with a lot of

      throw new RuntimeException("unimplemented");

      then you can start working with it right away, filling in the methods as
      you actually call them. In a big spec like the HttpServlet stuff, I
      ended up having to implement very little of it.

      > But, I'd suggest that you try a different approach. Dependencies
      > like this to the container should be limited to the very thinnest
      > layer of the web application.[...]
      > I'd also suggest that you don't pass a raw Connection around
      > either, but instead wrap the database access in a DAO of some
      > sort so you can test without needing actual database access.

      Both excellent recommendations! Carfield, heed this man! :-)


      William Pietri <william@...>
    Your message has been successfully submitted and would be delivered to recipients shortly.