RegisteredJobStatisticJob extends AbstractStatisticJob { @Override public void execute(final JobExecutionContext context) { Optional<JobRegisterStatistics> latestOne = repository.findLatestJobRegisterStatistics(); latestOne.ifPresent(this::fillBlankIfNeeded); 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);  }
@Test public void assertExecuteWhenRepositoryIsEmpty() { Optional<JobRegisterStatistics> latestOne = Optional.empty(); when(repository.findLatestJobRegisterStatistics()).thenReturn(latestOne); when(repository.add(any(JobRegisterStatistics.class))).thenReturn(true); when(configurationService.loadAll()).thenReturn(Collections.singletonList(CloudJobConfigurationBuilder.createCloudJobConfiguration("test_job"))); registeredJobStatisticJob.execute(null); verify(repository).findLatestJobRegisterStatistics(); verify(repository).add(any(JobRegisterStatistics.class)); verify(configurationService).loadAll(); }
@Test public void assertExecute() { 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(Collections.singletonList(CloudJobConfigurationBuilder.createCloudJobConfiguration("test_job"))); registeredJobStatisticJob.execute(null); verify(repository).findLatestJobRegisterStatistics(); verify(repository, times(3)).add(any(JobRegisterStatistics.class)); verify(configurationService).loadAll(); }