DeleteServlet extends HttpServlet { @Override public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { Document document = Document.newBuilder().addField(Field.newBuilder().setName("f").setText("v")).build(); try { Utils.indexADocument(SEARCH_INDEX, document); } catch (InterruptedException e) { } try { while (true) { List<String> docIds = new ArrayList<>(); GetRequest request = GetRequest.newBuilder().setReturningIdsOnly(true).build(); GetResponse<Document> response = getIndex().getRange(request); if (response.getResults().isEmpty()) { break; } for (Document doc : response) { docIds.add(doc.getId()); } getIndex().delete(docIds); } } catch (RuntimeException e) { LOG.log(Level.SEVERE, "Failed to delete documents", e); } PrintWriter out = resp.getWriter(); out.println("Deleted documents."); }  @Override void doGet(HttpServletRequest req, HttpServletResponse resp);  }
@Test public void doGet_successfulyInvoked() throws Exception { servletUnderTest.doGet(mockRequest, mockResponse); assertWithMessage("DeleteServlet response") .that(responseWriter.toString()) .contains("Deleted documents."); }