SignGuestbookServlet extends HttpServlet { @Override public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException { Greeting greeting; UserService userService = UserServiceFactory.getUserService(); User user = userService.getCurrentUser(); String guestbookName = req.getParameter("guestbookName"); String content = req.getParameter("content"); if (user != null) { greeting = new Greeting(guestbookName, content, user.getUserId(), user.getEmail()); } else { greeting = new Greeting(guestbookName, content); } ObjectifyService.ofy().save().entity(greeting).now(); resp.sendRedirect("/guestbook.jsp?guestbookName=" + guestbookName); }  @Override void doPost(HttpServletRequest req, HttpServletResponse resp);  }
@Test public void doPost_userNotLoggedIn() throws Exception { servletUnderTest.doPost(mockRequest, mockResponse); Greeting greeting = ObjectifyService.ofy().load().type(Greeting.class) .ancestor(Key.create(Guestbook.class, "default2")).first().now(); assertEquals(greeting.content, testPhrase); }