### Question:
GroupSelector extends HttpServlet { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession session = request.getSession(true); int i = 0; while (request.getParameter("MyExpGroup" + i) != null || request.getAttribute("MyExpGroup" + i) != null) { String groupName = ""; String groupParam = request.getParameter("MyExpGroup" + i); String groupAttrib = (String) request.getAttribute("MyExpGroup" + i); if (groupParam != null) { groupName = groupParam; } else if (groupAttrib != null) { groupName = groupAttrib; } session.setAttribute("selectedGroupName" + i, groupName); String workflowUrl = ""; String workflowParam = request.getParameter("MyExpWorkflow" + i); String workflowAttrib = (String) request.getAttribute("MyExpWorkflow" + i); if (workflowParam != null) { workflowUrl = workflowParam; } else if (workflowAttrib != null) { workflowUrl = workflowAttrib; } session.setAttribute("currentWfId" + i, workflowUrl); i++; } RequestDispatcher rd = getServletContext().getRequestDispatcher("/"); rd.forward(request, response); } GroupSelector(); 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); when(request.getSession(true)).thenReturn(sesion); when(request.getParameter("MyExpGroup0")).thenReturn("prueba0"); when(request.getAttribute("MyExpGroup1")).thenReturn("prueba1"); when(request.getParameter("MyExpWorkflow0")).thenReturn("prueba0"); when(request.getAttribute("MyExpWorkflow1")).thenReturn("prueba1"); when(config.getServletContext()).thenReturn(context); when(context.getRequestDispatcher("/")).thenReturn(dispatcher); GroupSelector group = new GroupSelector(); try { group.init(config); group.doPost(request, response); } catch (ServletException ex) { fail("Should not raise exception " + ex.toString()); } catch (IOException ex) { fail("Should not raise exception " + ex.toString()); } }