### Question:
SOAPinputs extends HttpServlet { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setAttribute("round2", "round2"); response.setContentType("text/html"); HttpSession session = request.getSession(); SoapService service = null; if(session.getAttribute("serviceObject") != null) { service = (SoapService)session.getAttribute("serviceObject"); } List<SoapOperation> soapOperations = service.getOperations(); if (soapOperations != null) { for (SoapOperation op : soapOperations) { if (op.getName().equals( request.getParameter("currentOperation"))) { session.setAttribute("currentOperation", op); break; } } } String displayDefaults = request.getParameter("displayDefaults"); if (displayDefaults != null) { session.setAttribute("displayDefaults", true); } else { session.setAttribute("displayDefaults", false); } RequestDispatcher rd = getServletContext().getRequestDispatcher( "/interface.jsp"); rd.forward(request, response); } SOAPinputs(); void init(ServletConfig config);  }### Answer:
@Test public void testDoPost() throws Exception { HttpServletRequest request = mock(HttpServletRequest.class); HttpServletResponse response = mock(HttpServletResponse.class); HttpSession sesion = mock(HttpSession.class); ServletConfig config = mock(ServletConfig.class); ServletContext context = mock(ServletContext.class); RequestDispatcher dispatcher = mock(RequestDispatcher.class); SoapService service = new SoapService("http: when(config.getServletContext()).thenReturn(context); when(context.getRequestDispatcher("/interface.jsp")).thenReturn(dispatcher); when(sesion.getAttribute("serviceObject")).thenReturn(service); when(request.getSession()).thenReturn(sesion); when(request.getParameter("displayDefaults")).thenReturn("true"); SOAPinputs info = new SOAPinputs(); try { info.init(config); info.doPost(request, response); } catch (ServletException ex) { fail("Should not raise exception "+ex.toString()); } catch (IOException ex) { fail("Should not raise exception "+ex.toString()); } }