### Question:
ScheduleServiceImpl implements ScheduleService { @Override public StatusResponse getAllJobs() { JobResponse jobResponse; List<JobResponse> jobs = new ArrayList<>(); int numOfRunningJobs = 0; int numOfGroups = 0; int numOfAllJobs = 0; try { Scheduler scheduler = schedulerFactoryBean.getScheduler(); for (String groupName : scheduler.getJobGroupNames()) { numOfGroups++; for (JobKey jobKey : scheduler.getJobKeys(GroupMatcher.jobGroupEquals(groupName))) { List<Trigger> triggers = (List<Trigger>) scheduler.getTriggersOfJob(jobKey); jobResponse = JobResponse.builder() .jobName(jobKey.getName()) .groupName(jobKey.getGroup()) .scheduleTime(DateTimeUtils.toString(triggers.get(0).getStartTime())) .lastFiredTime(DateTimeUtils.toString(triggers.get(0).getPreviousFireTime())) .nextFireTime(DateTimeUtils.toString(triggers.get(0).getNextFireTime())) .build(); if (isJobRunning(jobKey)) { jobResponse.setJobStatus("RUNNING"); numOfRunningJobs++; } else { String jobState = getJobState(jobKey); jobResponse.setJobStatus(jobState); } numOfAllJobs++; jobs.add(jobResponse); } } } catch (SchedulerException e) { log.error("[schedulerdebug] error while fetching all job info", e); throw new ApiException(ExceptionCode.SCHEDULER_GET_FAIL.getMessage(), e); } return StatusResponse.builder() .jobs(jobs) .numOfAllJobs(numOfAllJobs) .numOfRunningJobs(numOfRunningJobs) .numOfGroups(numOfGroups) .build(); }  @Override boolean addJob(JobRequest jobRequest, Class<? extends Job> jobClass); @Override boolean deleteJob(JobKey jobKey); @Override boolean updateJob(JobRequest jobRequest); @Override boolean pauseJob(JobKey jobKey); @Override boolean resumeJob(JobKey jobKey); @Override boolean stopJob(JobKey jobKey); @Override StatusResponse getAllJobs(); @Override boolean isJobRunning(JobKey jobKey); @Override boolean isJobExists(JobKey jobKey); @Override String getJobState(JobKey jobKey);  }### Answer:
@Test public void getAllJobs() throws SchedulerException { List triggers = new ArrayList(); addMockTrigger(triggers, testJobName, testGroupName); when(schedulerFactoryBean.getScheduler()).thenReturn(scheduler); when(scheduler.getJobGroupNames()).thenReturn(jobGroupNames); when(scheduler.getJobKeys(anyObject())).thenReturn(jobKeySet); when(scheduler.getJobDetail(anyObject())).thenReturn(new JobDetailImpl(testJobName, testGroupName, MockJob.class)); when(scheduler.getTriggersOfJob(anyObject())).thenReturn(triggers).thenReturn(triggers); when(scheduler.getTriggerState(anyObject())).thenReturn(Trigger.TriggerState.BLOCKED); StatusResponse result = scheduleService.getAllJobs(); log.info("result : {}", result); assertThat(result.getJobs().size()).isEqualTo(1); assertThat(result.getJobs().get(0).getJobName()).isEqualTo(testJobName); verify(schedulerFactoryBean, times(3)).getScheduler(); verify(scheduler).getJobGroupNames(); verify(scheduler).getJobKeys(anyObject()); verify(scheduler).getJobDetail(anyObject()); verify(scheduler, times(2)).getTriggersOfJob(anyObject()); verify(scheduler).getTriggerState(anyObject()); }
@Test public void getAllJobs_Exception시_Throw하는지_체크() { when(schedulerFactoryBean.getScheduler()).thenAnswer(invocation -> { throw new SchedulerException(); }); assertThatThrownBy(() -> scheduleService.getAllJobs()).hasMessage(ExceptionCode.SCHEDULER_GET_FAIL.getMessage()); }