### Question:
ExecutionScheduleManager { public boolean continueOnMisfire(JobExecutionContext jobExecutionContext) { if (jobExecutionContext != null) { Date scheduledTime = jobExecutionContext.getScheduledFireTime(); Long diff = DateUtils.getDateDifferenceInMinutes(scheduledTime); return (diff < configuration.getExecutionSchedulerMisfireToleration()); } return true; } @Inject  ExecutionScheduleManager(Configuration configuration,
                                  ExecutionScheduler executionScheduler,
                                  InternalTokenStorage tokenStorage,
                                  Clusters clusters,
                                  ActionDBAccessor actionDBAccessor,
                                  Gson gson); void start(); void stop(); boolean isSchedulerAvailable(); void scheduleJob(Trigger trigger); boolean continueOnMisfire(JobExecutionContext jobExecutionContext); void scheduleBatch(RequestExecution requestExecution); void updateBatchSchedule(RequestExecution requestExecution); void validateSchedule(Schedule schedule); void deleteAllJobs(RequestExecution requestExecution); Long executeBatchRequest(long executionId,
                                  long batchId,
                                  String clusterName); BatchRequestResponse getBatchRequestResponse(Long requestId, String clusterName); void updateBatchRequest(long executionId, long batchId, String clusterName,
                                 BatchRequestResponse batchRequestResponse,
                                 boolean statusOnly); boolean hasToleranceThresholdExceeded(Long executionId,
      String clusterName, Map<String, Integer> taskCounts); void finalizeBatch(long executionId, String clusterName); static final String USER_ID_HEADER; }### Answer:
@Test public void testFinalizeBeforeExit() throws Exception { ExecutionScheduleManager scheduleManagerMock = createMock(ExecutionScheduleManager.class); AbstractLinearExecutionJob executionJob = createMockBuilder(AbstractLinearExecutionJob.class) .addMockedMethods("finalizeExecution", "doWork") .withConstructor(scheduleManagerMock) .createMock(); JobExecutionContext context = createMock(JobExecutionContext.class); JobDetail jobDetail = createMock(JobDetail.class); JobDataMap jobDataMap = createMock(JobDataMap.class); expect(context.getJobDetail()).andReturn(jobDetail).anyTimes(); expect(context.getMergedJobDataMap()).andReturn(jobDataMap).anyTimes(); expect(jobDetail.getKey()).andReturn(new JobKey("TestJob")); expect(jobDataMap.getWrappedMap()).andReturn(new HashMap<>()); expect(scheduleManagerMock.continueOnMisfire(context)).andReturn(true); executionJob.doWork(EasyMock.anyObject()); expectLastCall().andThrow(new AmbariException("Test Exception")).anyTimes(); executionJob.finalizeExecution(EasyMock.anyObject()); expectLastCall().once(); replay(scheduleManagerMock, executionJob, context, jobDataMap, jobDetail); try { executionJob.execute(context); } catch (Exception ae) { assertThat(ae, instanceOf(JobExecutionException.class)); JobExecutionException je = (JobExecutionException) ae; Assert.assertEquals("Test Exception", je.getUnderlyingException().getMessage()); } verify(scheduleManagerMock, executionJob, context, jobDataMap, jobDetail); }