DeleteServlet extends HttpServlet { @Override public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException { String gameId = request.getParameter("gameKey"); Objectify ofy = ObjectifyService.ofy(); Game game = ofy.load().type(Game.class).id(gameId).safe(); UserService userService = UserServiceFactory.getUserService(); String currentUserId = userService.getCurrentUser().getUserId(); game.deleteChannel(currentUserId); }  @Override void doPost(HttpServletRequest request, HttpServletResponse response);  }
@Test public void doPost_noGameKey() throws Exception { try { servletUnderTest.doPost(mockRequest, mockResponse); fail("Should not succeed with no gameKey specified."); } catch (IllegalArgumentException e) { assertThat(e.getMessage()).startsWith("id 'null'"); } }
@Test public void doPost_deleteGame() throws Exception { Objectify ofy = ObjectifyService.ofy(); Game game = new Game(USER_ID, "my-opponent", " ", true); ofy.save().entity(game).now(); String gameKey = game.getId(); when(mockRequest.getParameter("gameKey")).thenReturn(gameKey); MockHttpTransport mockHttpTransport = spy( new MockHttpTransport() { @Override public LowLevelHttpRequest buildRequest(String method, String url) throws IOException { return new MockLowLevelHttpRequest() { @Override public LowLevelHttpResponse execute() throws IOException { MockLowLevelHttpResponse response = new MockLowLevelHttpResponse(); response.setStatusCode(200); return response; } }; } }); FirebaseChannel.getInstance().httpTransport = mockHttpTransport; servletUnderTest.doPost(mockRequest, mockResponse); verify(mockHttpTransport, times(1)) .buildRequest(eq("DELETE"), Matchers.matches(FIREBASE_DB_URL + "/channels/[\\w-]+.json$")); }