IndexServlet extends HttpServlet { @Override public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { PrintWriter out = resp.getWriter(); Document document = Document.newBuilder() .setId("AZ125") .addField(Field.newBuilder().setName("myField").setText("myValue")) .build(); try { Utils.indexADocument(INDEX, document); } catch (InterruptedException e) { out.println("Interrupted"); return; } out.println("Indexed a new document."); IndexSpec indexSpec = IndexSpec.newBuilder().setName(INDEX).build(); Index index = SearchServiceFactory.getSearchService().getIndex(indexSpec); Document doc = index.get("AZ125"); GetResponse<Document> docs = index.getRange(GetRequest.newBuilder().setStartId("AZ125").setLimit(100).build()); out.println("myField: " + docs.getResults().get(0).getOnlyField("myField").getText()); }  @Override void doGet(HttpServletRequest req, HttpServletResponse resp);  }
@Test public void doGet_successfulyInvoked() throws Exception { servletUnderTest.doGet(mockRequest, mockResponse); assertWithMessage("IndexServlet response") .that(responseWriter.toString()) .contains("myField: myValue"); }