### Question:
RegisteredJobStatisticJob extends AbstractStatisticJob { @Override public void execute(final JobExecutionContext context) throws JobExecutionException { Optional<JobRegisterStatistics> latestOne = repository.findLatestJobRegisterStatistics(); if (latestOne.isPresent()) { fillBlankIfNeeded(latestOne.get()); } int registeredCount = configurationService.loadAll().size(); JobRegisterStatistics jobRegisterStatistics = new JobRegisterStatistics(registeredCount, StatisticTimeUtils.getCurrentStatisticTime(execInterval)); log.debug("Add jobRegisterStatistics, registeredCount is:{}", registeredCount); repository.add(jobRegisterStatistics); }  @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<JobRegisterStatistics> latestOne = Optional.absent(); when(repository.findLatestJobRegisterStatistics()).thenReturn(latestOne); when(repository.add(any(JobRegisterStatistics.class))).thenReturn(true); when(configurationService.loadAll()).thenReturn(Lists.newArrayList(CloudJobConfigurationBuilder.createCloudJobConfiguration("test_job"))); registeredJobStatisticJob.execute(null); verify(repository).findLatestJobRegisterStatistics(); verify(repository).add(any(JobRegisterStatistics.class)); verify(configurationService).loadAll(); }
@Test public void assertExecute() throws SchedulerException { Optional<JobRegisterStatistics> latestOne = Optional.of(new JobRegisterStatistics(0, StatisticTimeUtils.getStatisticTime(StatisticInterval.DAY, -3))); when(repository.findLatestJobRegisterStatistics()).thenReturn(latestOne); when(repository.add(any(JobRegisterStatistics.class))).thenReturn(true); when(configurationService.loadAll()).thenReturn(Lists.newArrayList(CloudJobConfigurationBuilder.createCloudJobConfiguration("test_job"))); registeredJobStatisticJob.execute(null); verify(repository).findLatestJobRegisterStatistics(); verify(repository, times(3)).add(any(JobRegisterStatistics.class)); verify(configurationService).loadAll(); }