@Test public void testDoGet() throws IOException { final HttpServletRequest request = mock(HttpServletRequest.class); final HttpServletResponse response = mock(HttpServletResponse.class); final StringWriter stringWriter = new StringWriter(); when(response.getWriter()).thenReturn(new PrintWriter(stringWriter)); guestbookServlet.doGet(request, response); final User currentUser = UserServiceFactory.getUserService().getCurrentUser(); assertEquals("Hello, " + currentUser.getNickname() + "\n", stringWriter.toString()); }
@Override public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { final UserService userService = UserServiceFactory.getUserService(); final User currentUser = userService.getCurrentUser(); if (currentUser != null) { resp.setContentType("text/plain"); resp.getWriter().println("Hello, " + currentUser.getNickname()); } else { resp.sendRedirect(userService.createLoginURL(req.getRequestURI())); } }
GuestbookServlet extends HttpServlet { @Override public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { final UserService userService = UserServiceFactory.getUserService(); final User currentUser = userService.getCurrentUser(); if (currentUser != null) { resp.setContentType("text/plain"); resp.getWriter().println("Hello, " + currentUser.getNickname()); } else { resp.sendRedirect(userService.createLoginURL(req.getRequestURI())); } } }
GuestbookServlet extends HttpServlet { @Override public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { final UserService userService = UserServiceFactory.getUserService(); final User currentUser = userService.getCurrentUser(); if (currentUser != null) { resp.setContentType("text/plain"); resp.getWriter().println("Hello, " + currentUser.getNickname()); } else { resp.sendRedirect(userService.createLoginURL(req.getRequestURI())); } }  }
GuestbookServlet extends HttpServlet { @Override public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { final UserService userService = UserServiceFactory.getUserService(); final User currentUser = userService.getCurrentUser(); if (currentUser != null) { resp.setContentType("text/plain"); resp.getWriter().println("Hello, " + currentUser.getNickname()); } else { resp.sendRedirect(userService.createLoginURL(req.getRequestURI())); } }  @Override void doGet(HttpServletRequest req, HttpServletResponse resp); }
GuestbookServlet extends HttpServlet { @Override public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { final UserService userService = UserServiceFactory.getUserService(); final User currentUser = userService.getCurrentUser(); if (currentUser != null) { resp.setContentType("text/plain"); resp.getWriter().println("Hello, " + currentUser.getNickname()); } else { resp.sendRedirect(userService.createLoginURL(req.getRequestURI())); } }  @Override void doGet(HttpServletRequest req, HttpServletResponse resp);  }