### Question:
UserCreateServlet extends HttpServlet { @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) { String name = req.getParameter("name"); String login = req.getParameter("login"); String email = req.getParameter("email"); String role = req.getParameter("role"); String password = req.getParameter("password"); String country = req.getParameter("country"); String city = req.getParameter("city"); String message = ""; String error = ""; User newUser = new User(name, login, email, role, password); newUser.setCountry(country); newUser.setCity(city); if (this.validator.add(newUser)) { message = "User was added"; } else { error = "Incorrect input data, please try again."; } req.setAttribute("message", message); req.setAttribute("error", error); try { req.getRequestDispatcher("/WEB-INF/views/create_user.jsp").forward(req, resp); } catch (ServletException | IOException e) { LOG.error(e.getMessage(), e); } }    }### Answer:
@Test public void ifCreateUserThenValidateServiceReturnHim() throws ServletException, IOException { when(this.request.getParameter("name")).thenReturn("CreateTest"); when(this.request.getParameter("login")).thenReturn("CreateTestLogin"); when(this.request.getParameter("email")).thenReturn("testEmail"); when(this.request.getParameter("role")).thenReturn("user"); when(this.request.getParameter("password")).thenReturn("password"); when(this.request.getRequestDispatcher("/WEB-INF/views/create_user.jsp")).thenReturn(this.dispatcher); this.testServlet.doPost(this.request, this.response); boolean createResult = false; int userId = 0; for (User usr : this.validator.findAll()) { if (usr.getName().equals("CreateTest") && usr.getLogin().equals("CreateTestLogin") && usr.getEmail().equals("testEmail") && usr.getPassword().equals("password")) { createResult = true; userId = usr.getId(); } } this.validator.delete(userId); assertTrue(createResult); verify(this.request).setAttribute("message", "User was added"); verify(this.dispatcher).forward(request, response); }
@Test public void ifCreateUserWithInvalidParametersThenServletReturnErrorText() throws ServletException, IOException { String userName = "testInvalidInputUser"; when(this.request.getParameter("name")).thenReturn(userName); when(this.request.getRequestDispatcher("/WEB-INF/views/create_user.jsp")).thenReturn(this.dispatcher); this.testServlet.doPost(this.request, this.response); verify(this.request).setAttribute("error", "Incorrect input data, please try again."); verify(this.dispatcher).forward(this.request, this.response); for (User usr : this.validator.findAll()) { assertNotEquals(usr.getName(), userName); } }