### Question:
ErrorServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { handleError(request, response); }    }### Answer:
@Test public void testServlet() throws Exception { String testErrorMsg = "test-error"; int testErrorCode = 400; StringWriter stringWriter = new StringWriter(); HttpServletRequest request = mock(HttpServletRequest.class); HttpServletResponse response = mock(HttpServletResponse.class); when(request.getAttribute("javax.servlet.error.message")).thenReturn(testErrorMsg); when(request.getAttribute("javax.servlet.error.status_code")).thenReturn(testErrorCode); when(response.getWriter()).thenReturn(new PrintWriter(stringWriter)); new ErrorServlet().doGet(request, response); JSONObject json = new JSONObject(stringWriter.toString().trim()); assertEquals("Error message is different.", testErrorMsg, json.getString(JsonTags.WORKFLOW_ACTION_ERROR_MESSAGE)); assertEquals("Http code is different", testErrorCode, json.getInt(JsonTags.HTTP_STATUS_CODE)); }