IndexesServlet extends HttpServlet { @Override public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException { Query q = new Query("Widget") .setFilter( CompositeFilterOperator.and( new FilterPredicate("x", FilterOperator.EQUAL, 1), new FilterPredicate("y", FilterOperator.EQUAL, "red"))) .addSort("date", Query.SortDirection.ASCENDING); List<Entity> results = datastore.prepare(q).asList(FetchOptions.Builder.withDefaults()); PrintWriter out = resp.getWriter(); out.printf("Got %d widgets.\n", results.size()); } IndexesServlet(); @Override void doGet(HttpServletRequest req, HttpServletResponse resp);  }
@Test public void doGet_emptyDatastore_writesNoWidgets() throws Exception { servletUnderTest.doGet(mockRequest, mockResponse); assertWithMessage("IndexesServlet response") .that(responseWriter.toString()) .isEqualTo("Got 0 widgets.\n"); }
@SuppressWarnings("VariableDeclarationUsageDistance") @Test public void doGet_repeatedPropertyEntities_writesWidgets() throws Exception { DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(); Entity widget = new Entity("Widget"); widget.setProperty("x", Arrays.asList(1, 2, 3, 4)); widget.setProperty("y", Arrays.asList("red", "green", "blue")); widget.setProperty("date", new Date()); datastore.put(widget); servletUnderTest.doGet(mockRequest, mockResponse); assertWithMessage("IndexesServlet response") .that(responseWriter.toString()) .isEqualTo("Got 1 widgets.\n"); }