### Question:
JobRunningStatisticJob extends AbstractStatisticJob { @Override public void execute(final JobExecutionContext context) throws JobExecutionException { Map<String, Set<TaskContext>> allRunningTasks = runningService.getAllRunningTasks(); statisticJob(getJobRunningCount(allRunningTasks)); statisticTask(getTaskRunningCount(allRunningTasks)); } JobRunningStatisticJob(final CoordinatorRegistryCenter registryCenter, final StatisticRdbRepository rdbRepository); @Override JobDetail buildJobDetail(); @Override Trigger buildTrigger(); @Override Map<String, Object> getDataMap(); @Override void execute(final JobExecutionContext context);  }### Answer:
@Test public void assertExecuteWhenRepositoryIsEmpty() throws SchedulerException { Optional<JobRunningStatistics> latestJobRunningStatistics = Optional.absent(); Optional<TaskRunningStatistics> latestTaskRunningStatistics = Optional.absent(); Mockito.when(repository.findLatestJobRunningStatistics()).thenReturn(latestJobRunningStatistics); Mockito.when(repository.findLatestTaskRunningStatistics()).thenReturn(latestTaskRunningStatistics); Mockito.when(repository.add(ArgumentMatchers.any(JobRunningStatistics.class))).thenReturn(true); Mockito.when(repository.add(ArgumentMatchers.any(TaskRunningStatistics.class))).thenReturn(true); Mockito.when(runningService.getAllRunningTasks()).thenReturn(Collections.<String, Set<TaskContext>>emptyMap()); jobRunningStatisticJob.execute(null); Mockito.verify(repository).findLatestJobRunningStatistics(); Mockito.verify(repository).add(ArgumentMatchers.any(JobRunningStatistics.class)); Mockito.verify(repository).add(ArgumentMatchers.any(TaskRunningStatistics.class)); Mockito.verify(runningService).getAllRunningTasks(); }
@Test public void assertExecute() throws SchedulerException { Optional<JobRunningStatistics> latestJobRunningStatistics = Optional.of(new JobRunningStatistics(0, StatisticTimeUtils.getStatisticTime(StatisticInterval.MINUTE, -3))); Optional<TaskRunningStatistics> latestTaskRunningStatistics = Optional.of(new TaskRunningStatistics(0, StatisticTimeUtils.getStatisticTime(StatisticInterval.MINUTE, -3))); Mockito.when(repository.findLatestJobRunningStatistics()).thenReturn(latestJobRunningStatistics); Mockito.when(repository.findLatestTaskRunningStatistics()).thenReturn(latestTaskRunningStatistics); Mockito.when(repository.add(ArgumentMatchers.any(JobRunningStatistics.class))).thenReturn(true); Mockito.when(repository.add(ArgumentMatchers.any(TaskRunningStatistics.class))).thenReturn(true); Map<String, Set<TaskContext>> jobMap = new HashMap<>(1); Set<TaskContext> jobSet = new HashSet<>(1); jobSet.add(TaskContext.from(TaskNode.builder().jobName("test_job").build().getTaskNodeValue())); jobMap.put("test_job", jobSet); Mockito.when(runningService.getAllRunningTasks()).thenReturn(jobMap); jobRunningStatisticJob.execute(null); Mockito.verify(repository).findLatestJobRunningStatistics(); Mockito.verify(repository).findLatestTaskRunningStatistics(); Mockito.verify(repository, Mockito.times(3)).add(ArgumentMatchers.any(JobRunningStatistics.class)); Mockito.verify(repository, Mockito.times(3)).add(ArgumentMatchers.any(TaskRunningStatistics.class)); Mockito.verify(runningService).getAllRunningTasks(); }