### Question:
AggregationEngine implements Runnable { @Trace protected void processJobBatch(JobQueueBatch job) { try { MDC.put(MDCConstants.JOB_ID, job.getJobID().toString()); MDC.put(MDCConstants.JOB_BATCH_ID, job.getBatchID().toString()); logger.info("Processing job, exporting to: {}.", this.operationsConfig.getExportPath()); logger.debug("Has {} attributed beneficiaries", job.getPatients().size()); Optional<String> nextPatientID = job.fetchNextPatient(aggregatorID); while (nextPatientID.isPresent()) { String patientId = nextPatientID.get(); nextPatientID = processPatient(job, patientId); } MDC.remove(MDCConstants.PATIENT_ID); if (this.isRunning()) { logger.info("COMPLETED job"); calculateFileMetadata(job); this.queue.completeBatch(job, aggregatorID); } else { logger.info("PAUSED job"); this.queue.pauseBatch(job, aggregatorID); } } catch (Exception error) { try { logger.error("FAILED job", error); this.queue.failBatch(job, aggregatorID); } catch (Exception failedBatchException) { logger.error("FAILED to mark job {} batch {} as failed. Batch will remain in the running state, and stuck job logic will retry this in 5 minutes...", job.getJobID(), job.getBatchID(), failedBatchException); } } } @Inject  AggregationEngine(@AggregatorID UUID aggregatorID, IJobQueue queue, OperationsConfig operationsConfig, JobBatchProcessor jobBatchProcessor); @Override void run(); void stop(); Boolean isRunning(); static void setGlobalErrorHandler(); UUID getAggregatorID();  }### Answer:
@Test public void testUnhealthyIfProcessJobBatchThrowsException() throws InterruptedException { Mockito.doThrow(new RuntimeException("Error")).when(engine).processJobBatch(Mockito.any(JobQueueBatch.class)); final var orgID = UUID.randomUUID(); queue.createJob( orgID, TEST_PROVIDER_ID, Collections.singletonList("1"), Collections.singletonList(ResourceType.Patient), null, MockBlueButtonClient.BFD_TRANSACTION_TIME ); AggregationEngineHealthCheck healthCheck = new AggregationEngineHealthCheck(engine); Assert.assertTrue(healthCheck.check().isHealthy()); ExecutorService executor = Executors.newCachedThreadPool(); executor.execute(engine); executor.awaitTermination(2, TimeUnit.SECONDS); Assert.assertFalse(healthCheck.check().isHealthy()); }