CronJobManagerImpl implements CronJobManager { @Override public Map<IJobKey, CrontabEntry> getScheduledJobs() { ImmutableMap.Builder<IJobKey, CrontabEntry> scheduledJobs = ImmutableMap.builder(); try { for (JobKey jobKey : scheduler.getJobKeys(GroupMatcher.anyGroup())) { Optional<CronTrigger> trigger = FluentIterable.from(scheduler.getTriggersOfJob(jobKey)) .filter(CronTrigger.class) .first(); if (trigger.isPresent()) { scheduledJobs.put( Quartz.auroraJobKey(jobKey), Quartz.crontabEntry(trigger.get())); } } } catch (SchedulerException e) { throw Throwables.propagate(e); } return scheduledJobs.build(); } @Inject  CronJobManagerImpl(Storage storage, Scheduler scheduler, TimeZone timeZone); @Override void startJobNow(final IJobKey jobKey); @Override void updateJob(final SanitizedCronJob config); @Override void createJob(final SanitizedCronJob cronJob); @Override boolean deleteJob(final IJobKey jobKey); @Override Map<IJobKey, CrontabEntry> getScheduledJobs();  }
@Test public void testGetScheduledJobs() throws Exception { CronTrigger cronTrigger = createMock(CronTrigger.class); expect(scheduler.getJobKeys(anyObject())) .andReturn(ImmutableSet.of(QuartzTestUtil.QUARTZ_JOB_KEY)); EasyMock. <List<? extends Trigger>>expect(scheduler.getTriggersOfJob(QuartzTestUtil.QUARTZ_JOB_KEY)) .andReturn(ImmutableList.of(cronTrigger)); expect(cronTrigger.getDescription()).andReturn("* * * * *"); control.replay(); Map<IJobKey, CrontabEntry> scheduledJobs = cronJobManager.getScheduledJobs(); assertEquals(CrontabEntry.parse("* * * * *"), scheduledJobs.get(QuartzTestUtil.AURORA_JOB_KEY)); }
@Test public void testGetScheduledJobsEmpty() throws Exception { expect(scheduler.getJobKeys(anyObject())) .andReturn(ImmutableSet.of(QuartzTestUtil.QUARTZ_JOB_KEY)); EasyMock. <List<? extends Trigger>>expect(scheduler.getTriggersOfJob(QuartzTestUtil.QUARTZ_JOB_KEY)) .andReturn(ImmutableList.of()); control.replay(); assertEquals(ImmutableMap.of(), cronJobManager.getScheduledJobs()); }
@Test(expected = RuntimeException.class) public void testGetScheduledJobsFails() throws Exception { expect(scheduler.getJobKeys(anyObject())) .andReturn(ImmutableSet.of(QuartzTestUtil.QUARTZ_JOB_KEY)); EasyMock. <List<? extends Trigger>>expect(scheduler.getTriggersOfJob(QuartzTestUtil.QUARTZ_JOB_KEY)) .andThrow(new SchedulerException()); control.replay(); cronJobManager.getScheduledJobs(); }