GetAllJobDetailsHandler implements OutputOperationHandler<GetAllJobDetails, CloseableIterable<JobDetail>> { @Override public CloseableIterable<JobDetail> doOperation(final GetAllJobDetails operation, final Context context, final Store store) throws OperationException { if (null == store.getJobTracker()) { throw new OperationException("The Job Tracker has not been configured", SERVICE_UNAVAILABLE); } return store.getJobTracker().getAllJobs(context.getUser()); }  @Override CloseableIterable<JobDetail> doOperation(final GetAllJobDetails operation, final Context context, final Store store);  }
@Test public void shouldThrowExceptionIfJobTrackerIsNotConfigured() { final GetAllJobDetailsHandler handler = new GetAllJobDetailsHandler(); final GetAllJobDetails operation = mock(GetAllJobDetails.class); final Store store = mock(Store.class); final User user = mock(User.class); given(store.getJobTracker()).willReturn(null); try { handler.doOperation(operation, new Context(user), store); fail("Exception expected"); } catch (final OperationException e) { assertNotNull(e.getMessage()); } }
@Test public void shouldGetAllJobDetailsByDelegatingToJobTracker() throws OperationException { final GetAllJobDetailsHandler handler = new GetAllJobDetailsHandler(); final GetAllJobDetails operation = mock(GetAllJobDetails.class); final Store store = mock(Store.class); final JobTracker jobTracker = mock(JobTracker.class); final User user = mock(User.class); final CloseableIterable<JobDetail> jobsDetails = mock(CloseableIterable.class); given(store.getJobTracker()).willReturn(jobTracker); given(jobTracker.getAllJobs(user)).willReturn(jobsDetails); final CloseableIterable<JobDetail> results = handler.doOperation(operation, new Context(user), store); assertSame(jobsDetails, results); }