### Question:
AddContactController extends HttpServlet { @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String firstName = request.getParameter("firstName"); String surname = request.getParameter("surname"); String birthday = request.getParameter("birthday"); String phone = request.getParameter("phone"); DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy"); Contact contact = new Contact(); contact.setFirstName(firstName); contact.setSurname(surname); try { contact.setBirthday(dateFormat.parse(birthday)); } catch(ParseException ex) { throw new ServletException("Wrong Birthday", ex); } contact.setPhone(phone); addressBook.addContact(contact); response.sendRedirect(successedSubmitRedirect); }  GlobalAddressBook getAddressBook(); void setAddressBook(GlobalAddressBook addressBook); String getSuccessedSubmitRedirect(); void setSuccessedSubmitRedirect(String successedSubmitRedirect); String getFormView(); void setFormView(String formView);  }### Answer:
@Test public void testDoPostGetParameters() throws ServletException, IOException { HttpServletRequest mockRequest = mock(HttpServletRequest.class); HttpServletResponse mockResponse = mock(HttpServletResponse.class); controller.doPost(mockRequest, mockResponse); verify(mockRequest, times(1)).getParameter(eq("firstName")); verify(mockRequest, times(1)).getParameter(eq("surname")); verify(mockRequest, times(1)).getParameter(eq("birthday")); verify(mockRequest, times(1)).getParameter(eq("phone")); }
@Test public void testDoPostAddContact() throws ServletException, IOException, ParseException { HttpServletRequest mockRequest = mock(HttpServletRequest.class); HttpServletResponse mockResponse = mock(HttpServletResponse.class); when(mockRequest.getParameter("firstName")).thenReturn("Pedro"); when(mockRequest.getParameter("surname")).thenReturn("Ballesteros"); when(mockRequest.getParameter("birthday")).thenReturn("8/1/1974"); when(mockRequest.getParameter("phone")).thenReturn("69696969"); controller.doPost(mockRequest, mockResponse); ArgumentCaptor<Contact> argument = ArgumentCaptor.forClass(Contact.class); verify(mockAddressbook).addContact(argument.capture()); Contact contact = argument.getValue(); assertEquals("Pedro", contact.getFirstName()); assertEquals("Ballesteros", contact.getSurname()); assertEquals(dateFormat.parse("8/1/1974"), contact.getBirthday()); assertEquals("69696969", contact.getPhone()); }