### Question:
ProcessFormServlet extends HttpServlet { @Override protected void doGet(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException { long processDefinitionId = -1L; long processInstanceId = -1L; long taskInstanceId = -1L; String taskName = null; final List<String> pathSegments = resourceRenderer.getPathSegments(request.getPathInfo()); final String user = request.getParameter(USER_ID_PARAM); final long userId = convertToLong(USER_ID_PARAM, user); final HttpSession session = request.getSession(); final APISession apiSession = (APISession) session.getAttribute(SessionUtil.API_SESSION_PARAM_KEY); try { if (pathSegments.size() > 1) { taskInstanceId = getTaskInstanceId(apiSession, pathSegments, userId); processInstanceId = getProcessInstanceId(pathSegments); processDefinitionId = getProcessDefinitionId(apiSession, pathSegments); } if (processDefinitionId == -1L && processInstanceId == -1L && taskInstanceId == -1L) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Either process name and version are required or process instance Id (with or without task name) or task instance Id."); return; } processDefinitionId = processFormService.ensureProcessDefinitionId(apiSession, processDefinitionId, processInstanceId, taskInstanceId); taskName = processFormService.getTaskName(apiSession, taskInstanceId); redirectToPageServlet(request, response, apiSession, processDefinitionId, processInstanceId, taskInstanceId, taskName); } catch (final Exception e) { handleException(response, processDefinitionId, taskName, processInstanceId != -1L, e); } }    }### Answer:
@Test public void should_get_not_found_when_invalid_processInstanceId() throws Exception { when(hsRequest.getPathInfo()).thenReturn("/processInstance/42/"); when(processFormService.ensureProcessDefinitionId(apiSession, -1L, 42L, -1L)).thenThrow(ArchivedProcessInstanceNotFoundException.class); formServlet.doGet(hsRequest, hsResponse); verify(hsResponse, times(1)).sendError(404, "Cannot find the process instance"); }