ProjectionServlet extends HttpServlet { @Override public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { resp.setContentType("text/plain"); resp.setCharacterEncoding("UTF-8"); PrintWriter out = resp.getWriter(); out.printf("Latest entries from guestbook: \n"); Key guestbookKey = KeyFactory.createKey("Guestbook", GUESTBOOK_ID); Query query = new Query("Greeting", guestbookKey); addGuestbookProjections(query); printGuestbookEntries(datastore, query, out); } ProjectionServlet(); @Override void doGet(HttpServletRequest req, HttpServletResponse resp);  }
@Test public void doGet_emptyDatastore_writesNoGreetings() throws Exception { servletUnderTest.doGet(mockRequest, mockResponse); assertWithMessage("ProjectionServlet response") .that(responseWriter.toString()) .doesNotContain("Message"); }
@Test public void doGet_manyGreetings_writesLatestGreetings() throws Exception { GuestbookStrong guestbook = new GuestbookStrong(GuestbookStrongServlet.GUESTBOOK_ID, new FakeClock()); guestbook.appendGreeting("Hello."); guestbook.appendGreeting("Güten Tag!"); guestbook.appendGreeting("Hi."); guestbook.appendGreeting("Hola."); servletUnderTest.doGet(mockRequest, mockResponse); String output = responseWriter.toString(); assertWithMessage("ProjectionServlet response").that(output).contains("Message Hello."); assertWithMessage("ProjectionServlet response").that(output).contains("Message Güten Tag!"); assertWithMessage("ProjectionServlet response").that(output).contains("Message Hola."); }