### Question:
ProcessInstanceService extends BaseService { @Transactional(rollbackFor = RuntimeException.class) public Map<String, Object> deleteProcessInstanceById(User loginUser, String projectName, Integer processInstanceId) { Map<String, Object> result = new HashMap<>(); Project project = projectMapper.queryByName(projectName); Map<String, Object> checkResult = projectService.checkProjectAndAuth(loginUser, project, projectName); Status resultEnum = (Status) checkResult.get(Constants.STATUS); if (resultEnum != Status.SUCCESS) { return checkResult; } ProcessInstance processInstance = processService.findProcessInstanceDetailById(processInstanceId); if (null == processInstance) { putMsg(result, Status.PROCESS_INSTANCE_NOT_EXIST, processInstanceId); return result; } processService.removeTaskLogFile(processInstanceId); int delete = processService.deleteWorkProcessInstanceById(processInstanceId); processService.deleteAllSubWorkProcessByParentId(processInstanceId); processService.deleteWorkProcessMapByParentId(processInstanceId); if (delete > 0) { putMsg(result, Status.SUCCESS); } else { putMsg(result, Status.DELETE_PROCESS_INSTANCE_BY_ID_ERROR); } return result; }  Map<String, Object> queryTopNLongestRunningProcessInstance(User loginUser, String projectName, int size, String startTime, String endTime); Map<String, Object> queryProcessInstanceById(User loginUser, String projectName, Integer processId); Map<String, Object> queryProcessInstanceList(User loginUser, String projectName, Integer processDefineId,
                                                        String startDate, String endDate,
                                                        String searchVal, String executorName, ExecutionStatus stateType, String host,
                                                        Integer pageNo, Integer pageSize); Map<String, Object> queryTaskListByProcessId(User loginUser, String projectName, Integer processId); Map<String, DependResult> parseLogForDependentResult(String log); Map<String, Object> querySubProcessInstanceByTaskId(User loginUser, String projectName, Integer taskId); Map<String, Object> updateProcessInstance(User loginUser, String projectName, Integer processInstanceId,
                                                     String processInstanceJson, String scheduleTime, Boolean syncDefine,
                                                     Flag flag, String locations, String connects); Map<String, Object> queryParentInstanceBySubId(User loginUser, String projectName, Integer subId); @Transactional(rollbackFor = RuntimeException.class) Map<String, Object> deleteProcessInstanceById(User loginUser, String projectName, Integer processInstanceId); Map<String, Object> viewVariables(Integer processInstanceId); Map<String, Object> viewGantt(Integer processInstanceId); List<ProcessInstance> queryByProcessDefineIdAndStatus(int processDefinitionId, int[] states); List<ProcessInstance> queryByProcessDefineId(int processDefinitionId,int size);  }### Answer:
@Test public void testDeleteProcessInstanceById() { String projectName = "project_test1"; User loginUser = getAdminUser(); Map<String, Object> result = new HashMap<>(); putMsg(result, Status.PROJECT_NOT_FOUNT, projectName); when(projectMapper.queryByName(projectName)).thenReturn(null); when(projectService.checkProjectAndAuth(loginUser, null, projectName)).thenReturn(result); Project project = getProject(projectName); putMsg(result, Status.SUCCESS, projectName); when(projectMapper.queryByName(projectName)).thenReturn(project); when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result); when(processService.findProcessInstanceDetailById(1)).thenReturn(null); }