### Question:
InfoGenerator extends HttpServlet { protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession session = request.getSession(true); String wfId = request.getParameter("id"); String urlString = "http: String user = (String) session.getAttribute("user"); String password = (String) session.getAttribute("password"); HttpClient client = new HttpClient(); GetMethod get; if(user!=null) { client.getParams().setAuthenticationPreemptive(true); client.getState().setCredentials( new AuthScope("www.myexperiment.org", 80), new UsernamePasswordCredentials(user, password)); get = new GetMethod(urlString); get.setDoAuthentication(true); client.executeMethod(get); } else { client.getParams().setAuthenticationPreemptive(false); get = new GetMethod(urlString); get.setDoAuthentication(false); client.executeMethod(get); } InputStream responseBody = get.getResponseBodyAsStream(); try { SAXBuilder builder = new SAXBuilder(); Document doc = builder.build(responseBody); WorkflowDetails details = new WorkflowDetails(); Element root = doc.getRootElement(); details.setTitle(root.getChild("title").getTextTrim()); details.setDescription(root.getChild("description").getTextTrim()); details.setImageUrl(root.getChild("preview").getTextTrim()); session.setAttribute("wfDetails", details); } catch (JDOMException e) { e.printStackTrace(); } RequestDispatcher rd = getServletContext().getRequestDispatcher("/info.jsp"); rd.forward(request, response); } InfoGenerator(); void init(ServletConfig config);  }### Answer:
@Test public void testDoGet() 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); ServletOutputStream stream = mock(ServletOutputStream.class); when(request.getSession(true)).thenReturn(sesion); when(request.getParameter("id")).thenReturn("16"); when(sesion.getAttribute("user")).thenReturn(null); when(sesion.getAttribute("password")).thenReturn(null); when(config.getServletContext()).thenReturn(context); when(context.getRequestDispatcher("/info.jsp")).thenReturn(dispatcher); InfoGenerator info = new InfoGenerator(); try { info.init(config); info.doGet(request, response); } catch (ServletException ex) { fail("Should not raise exception " + ex.toString()); } catch (IOException ex) { fail("Should not raise exception " + ex.toString()); } }