AceAutocompleteServlet extends SlingAllMethodsServlet { @Override protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { try (PrintWriter responseWriter = response.getWriter()) { Set<String> methodsSet = new TreeSet<>(); methodsSet.add(AecuBinding.BINDING_NAME); List<Method> methods = getPublicMethodsOfClass(AecuBinding.class); for (Method method : methods) { methodsSet.add(getCompletion(method)); Class extensionClass = method.getReturnType(); List<Method> publicMethods = getPublicMethodsOfClass(extensionClass); publicMethods.stream().forEach(n -> methodsSet.add(getCompletion(n))); } String responseString = new Gson().toJson(methodsSet.toArray(new String[] {})); responseWriter.write(responseString); response.setStatus(HttpStatus.SC_OK); } }    }
@Test public void test_doGet_response() throws IOException, ServletException { SlingHttpServletResponse responseMock = mock(SlingHttpServletResponse.class); PrintWriter writerMock = mock(PrintWriter.class); when(responseMock.getWriter()).thenReturn(writerMock); underTest.doGet(mock(SlingHttpServletRequest.class), responseMock); ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class); verify(writerMock, times(1)).write(captor.capture()); String actualJsonContent = captor.getValue(); assertNotNull(actualJsonContent); JsonArray actualJson = new Gson().fromJson(actualJsonContent, JsonArray.class); assertNotNull(actualJson); assertTrue(actualJson.size() > 5); assertTrue(actualJson.contains(new JsonPrimitive("aecu"))); assertTrue(actualJson.contains(new JsonPrimitive("contentUpgradeBuilder()"))); assertTrue(actualJson.contains(new JsonPrimitive("run()"))); }