### Question:
ScheduleServiceImpl implements ScheduleService { @Override public boolean addJob(JobRequest jobRequest, Class<? extends Job> jobClass) { JobKey jobKey = null; JobDetail jobDetail; Trigger trigger; try { trigger = JobUtils.createTrigger(jobRequest); jobDetail = JobUtils.createJob(jobRequest, jobClass, context); jobKey = JobKey.jobKey(jobRequest.getJobName(), jobRequest.getGroupName()); Date dt = schedulerFactoryBean.getScheduler().scheduleJob(jobDetail, trigger); log.debug("Job with jobKey : {} scheduled successfully at date : {}", jobDetail.getKey(), dt); JobHistory jobHistory = jobHistoryService.addJob(jobRequest); log.debug("jobHistory : {}", jobHistory); return true; } catch (SchedulerException e) { log.error("error occurred while scheduling with jobKey : {}", jobKey, e); throw new ApiException(ExceptionCode.SCHEDULER_ADD_FAIL.getMessage(), e); } }  @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 addJob() { JobRequest jobRequest = new JobRequest(); jobRequest.setCronExpression("0/10 * * ? * *"); jobRequest.setJobName(testJobName); jobRequest.setGroupName(testGroupName); JobHistory jobHistory = new JobHistory(); jobHistory.setJobName(testJobName); when(jobHistoryService.addJob(jobRequest)).thenReturn(jobHistory); when(schedulerFactoryBean.getScheduler()).thenReturn(scheduler); boolean result = scheduleService.addJob(jobRequest, CronJob.class); assertThat(result).isTrue(); verify(jobHistoryService).addJob(jobRequest); verify(schedulerFactoryBean).getScheduler(); }
@Test public void addJob_Exception시_Throw하는지_체크() { JobRequest jobRequest = new JobRequest(); jobRequest.setCronExpression("0/10 * * ? * *"); jobRequest.setJobName(testJobName); jobRequest.setGroupName(testGroupName); when(schedulerFactoryBean.getScheduler()).thenAnswer(invocation -> { throw new SchedulerException(); }); assertThatThrownBy(() -> scheduleService.addJob(jobRequest, CronJob.class)).hasMessage(ExceptionCode.SCHEDULER_ADD_FAIL.getMessage()); }