### Question:
WSDLinfo extends HttpServlet { @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession session = request.getSession(true); String wsdlURL = null; if (request.getParameter("wsId") != null) { wsdlURL = request.getParameter("wsId"); } else { wsdlURL = request.getParameter("wsdlURL"); logger.trace("Importing WSDL from URL " + wsdlURL); } String wsName = null; if (request.getParameter("wsName") != null) { wsName = request.getParameter("wsName"); session.setAttribute("wsName", wsName); } String key = "1234567891234567"; String wsUser = ""; if(request.getParameter("user")!=null) { if(request.getParameter("user") != "") { wsUser = Security.decrypt(request.getParameter("user"),key); session.setAttribute("wsUser", wsUser); } } String wsPass = ""; if(request.getParameter("pass")!=null) { if(request.getParameter("pass") != "") { wsPass = Security.decrypt(request.getParameter("pass"),key); session.setAttribute("wsPass", wsPass); } } logger.info("URL WSDL: " + wsdlURL); SoapService serviceObject = new SoapService(wsdlURL); request.setAttribute("round1", "round1"); session.setAttribute("wsdlURL", wsdlURL); session.setAttribute("serviceObject", serviceObject); RequestDispatcher rd = getServletContext().getRequestDispatcher( "/interface.jsp"); rd.forward(request, response); } WSDLinfo(); @Override void init(ServletConfig config); static String configLocation; }### 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); String key = "1234567891234567"; when(config.getServletContext()).thenReturn(context); when(context.getRequestDispatcher("/interface.jsp")).thenReturn(dispatcher); when(request.getParameter("wsId")).thenReturn(null); when(request.getParameter("wsdlURL")).thenReturn("http: when(request.getParameter("wsName")).thenReturn("nombre"); when(request.getParameter("user")).thenReturn(Security.encrypt("usuario",key)); when(request.getParameter("pass")).thenReturn(Security.encrypt("password",key)); when(request.getSession(true)).thenReturn(sesion); WSDLinfo info = new WSDLinfo(); 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()); } }