src/test/java/codeu/controller/RegisterServletTest.java
/**
   * Prints test message whenever the user attempts to register with a username that
   * is already being used.
   */
Prints test message whenever the user attempts to register with a username that
is already being used.
Prints test message whenever the user attempts to register with a username that is already being used .
@Test
  public void testDoPost_ExistingUser() throws IOException, ServletException {
    Mockito.when(mockRequest.getParameter("username")).thenReturn("existing username");
    Mockito.when(mockRequest.getParameter("password")).thenReturn("existing password");
    UserStore mockUserStore = Mockito.mock(UserStore.class);
    Mockito.when(mockUserStore.isUserRegistered("existing username")).thenReturn(true);
    registerServlet.setUserStore(mockUserStore);
    HttpSession mockSession = Mockito.mock(HttpSession.class);
    Mockito.when(mockRequest.getSession()).thenReturn(mockSession);
    registerServlet.doPost(mockRequest, mockResponse);
    Mockito.verify(mockUserStore, Mockito.never()).addUser(Mockito.any(User.class));
    Mockito.verify(mockRequest).setAttribute("error", "That username is already taken.");
    Mockito.verify(mockRequestDispatcher).forward(mockRequest,mockResponse);
  }
@ Test public void testDoPost_ExistingUser ( ) throws IOException , ServletException { Mockito . when ( mockRequest . getParameter ( "username" ) ) . thenReturn ( "existing username" ) ; Mockito . when ( mockRequest . getParameter ( "password" ) ) . thenReturn ( "existing password" ) ; UserStore mockUserStore = Mockito . mock ( UserStore . class ) ; Mockito . when ( mockUserStore . isUserRegistered ( "existing username" ) ) . thenReturn ( true ) ; registerServlet . setUserStore ( mockUserStore ) ; HttpSession mockSession = Mockito . mock ( HttpSession . class ) ; Mockito . when ( mockRequest . getSession ( ) ) . thenReturn ( mockSession ) ; registerServlet . doPost ( mockRequest , mockResponse ) ; Mockito . verify ( mockUserStore , Mockito . never ( ) ) . addUser ( Mockito . any ( User . class ) ) ; Mockito . verify ( mockRequest ) . setAttribute ( "error" , "That username is already taken." ) ; Mockito . verify ( mockRequestDispatcher ) . forward ( mockRequest , mockResponse ) ; }
Prints test message whenever the user attempts to register with a username that
 is already being used.
Prints test message whenever the user attempts to register with a username that is already being used .