### Question:
GridStatistics extends RegistryBasedServlet { @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { process(req, resp); } GridStatistics();  GridStatistics(GridRegistry registry);   }### Answer:
@Test public void testValidResponse() throws Exception { MockHttpServletRequest request = new MockHttpServletRequest(); request.addHeader("Accept", "*/*"); MockHttpServletResponse response = new MockHttpServletResponse(); List<BrowserStatistics> browserStatisticsList = new ArrayList<>(); BrowserStatisticsCollection t = new BrowserStatisticsCollection(); BrowserStatistics browserStatistics = t.new BrowserStatistics("chrome"); browserStatisticsList.add(browserStatistics); spy(GridStatistics.class); stub(method(GridStatistics.class, "getGridLoadResponse")).toReturn(browserStatisticsList); GridStatistics gridStatistics = new GridStatistics(); gridStatistics.doPost(request, response); Assert.assertEquals(response.getContentAsString(), "[{\"browserName\":\"chrome\",\"statistics\":{\"waitingRequests\":0,\"maxBrowserInstances\":0}}]", "Servlet output not matching"); }
@Test public void testEmptyResponse() throws Exception { MockHttpServletRequest request = new MockHttpServletRequest(); request.addHeader("Accept", "*/*"); MockHttpServletResponse response = new MockHttpServletResponse(); List<BrowserStatistics> browserStatisticsList = new ArrayList<>(); spy(GridStatistics.class); stub(method(GridStatistics.class, "getGridLoadResponse")).toReturn(browserStatisticsList); GridStatistics gridStatistics = new GridStatistics(); gridStatistics.doPost(request, response); Assert.assertEquals(response.getContentAsString(), "[]", "Servlet output not matching"); }