AjaxServlet extends HttpServlet { @Override protected void doPost(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { try { process(req, resp); } catch (final IOException e) { log.error("Cannot stream request", e); } }    }
@Test public void testDoPost() throws ServletException, IOException { final int uiContextID = 1; final int pObjectID = 2; final HttpServletRequest request = Mockito.mock(HttpServletRequest.class); Mockito.when(request.getHeader(ClientToServerModel.UI_CONTEXT_ID.name())).thenReturn(String.valueOf(uiContextID)); Mockito.when(request.getHeader(ClientToServerModel.OBJECT_ID.name())).thenReturn(String.valueOf(pObjectID)); final HttpServletResponse response = Mockito.mock(HttpServletResponse.class); ajaxServlet.doPost(request, response); Mockito.verify(response, Mockito.times(1)).sendError(ArgumentMatchers.eq(HttpServletResponse.SC_INTERNAL_SERVER_ERROR), ArgumentMatchers.anyString()); }