ScreenController implements HttpRequestHandler { @Override public void handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { AsyncContext asyncContext = request.startAsync(); if ("true".equals(request.getParameter("allPlayersScreen"))) { screenSender.scheduleUpdate(new PlayerScreenUpdateRequest(asyncContext, true, null)); } else { Set<String> playersToUpdate = request.getParameterMap().keySet(); screenSender.scheduleUpdate(new PlayerScreenUpdateRequest(asyncContext, false, playersToUpdate)); } } ScreenController();  ScreenController(RestScreenSender screenSender); @Override void handleRequest(HttpServletRequest request, HttpServletResponse response);  }
@Test public void shouldRequestUpdatesForPlayers() throws IOException, ServletException { request.addParameter("vasya", "vasya"); screenController.handleRequest(request, new MockHttpServletResponse()); verify(screenSender).scheduleUpdate(updateRequestCaptor.capture()); assertUpdateRequestContainsPlayer("vasya"); }
@Test public void shouldRequestUpdatesForAllPlayersScreen() throws IOException, ServletException { request.addParameter("vasya", "vasya"); request.addParameter("allPlayersScreen", "true"); screenController.handleRequest(request, new MockHttpServletResponse()); verify(screenSender).scheduleUpdate(updateRequestCaptor.capture()); PlayerScreenUpdateRequest updateRequest = updateRequestCaptor.getValue(); assertTrue(updateRequest.isForAllPlayers()); assertNull(updateRequest.getPlayersToUpdate()); }