### Question:
ProcessInstanceService extends BaseService { public Map<String, Object> viewGantt(Integer processInstanceId) throws Exception { Map<String, Object> result = new HashMap<>(); ProcessInstance processInstance = processInstanceMapper.queryDetailById(processInstanceId); if (processInstance == null) { throw new RuntimeException("workflow instance is null"); } GanttDto ganttDto = new GanttDto(); DAG<String, TaskNode, TaskNodeRelation> dag = processInstance2DAG(processInstance); List<String> nodeList = dag.topologicalSort(); ganttDto.setTaskNames(nodeList); List<Task> taskList = new ArrayList<>(); for (String node : nodeList) { TaskInstance taskInstance = taskInstanceMapper.queryByInstanceIdAndName(processInstanceId, node); if (taskInstance == null) { continue; } Date startTime = taskInstance.getStartTime() == null ? new Date() : taskInstance.getStartTime(); Date endTime = taskInstance.getEndTime() == null ? new Date() : taskInstance.getEndTime(); Task task = new Task(); task.setTaskName(taskInstance.getName()); task.getStartDate().add(startTime.getTime()); task.getEndDate().add(endTime.getTime()); task.setIsoStart(startTime); task.setIsoEnd(endTime); task.setStatus(taskInstance.getState().toString()); task.setExecutionDate(taskInstance.getStartTime()); task.setDuration(DateUtils.format2Readable(endTime.getTime() - startTime.getTime())); taskList.add(task); } ganttDto.setTasks(taskList); result.put(DATA_LIST, ganttDto); putMsg(result, Status.SUCCESS); 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 testViewGantt() throws Exception { ProcessInstance processInstance = getProcessInstance(); processInstance.setProcessInstanceJson(shellJson); TaskInstance taskInstance = getTaskInstance(); taskInstance.setState(ExecutionStatus.RUNNING_EXECUTION); taskInstance.setStartTime(new Date()); when(processInstanceMapper.queryDetailById(1)).thenReturn(processInstance); when(taskInstanceMapper.queryByInstanceIdAndName(Mockito.anyInt(), Mockito.any())).thenReturn(taskInstance); Map<String, Object> successRes = processInstanceService.viewGantt(1); Assert.assertEquals(Status.SUCCESS, successRes.get(Constants.STATUS)); }