### Question:
JobQueueBatch implements Serializable { public void setCompletedStatus(UUID aggregatorID) { if (this.status != JobStatus.RUNNING) { throw new JobQueueFailure(jobID, batchID, String.format("Cannot complete. JobStatus: %s", this.status)); } if (!this.patients.isEmpty() && (this.patientIndex == null || this.getPatients().size() != this.patientIndex + 1)) { throw new JobQueueFailure(jobID, batchID, String.format("Cannot complete. Job processing not finished. Only on patient %d of %d", this.getPatientIndex().orElse(-1) + 1, patients.size())); } this.verifyAggregatorID(aggregatorID); this.status = JobStatus.COMPLETED; this.aggregatorID = null; this.patientIndex = null; completeTime = OffsetDateTime.now(ZoneOffset.UTC); this.setUpdateTime(); } JobQueueBatch();  JobQueueBatch(UUID jobID,
                         UUID orgID,
                         String providerID,
                         List<String> patients,
                         List<ResourceType> resourceTypes,
                         OffsetDateTime since,
                         OffsetDateTime transactionTime); static Boolean isValidResourceType(ResourceType type); Boolean isValid(); UUID getBatchID(); UUID getJobID(); UUID getOrgID(); String getProviderID(); JobStatus getStatus(); Integer getPriority(); List<String> getPatients(); Optional<Integer> getPatientIndex(); List<ResourceType> getResourceTypes(); Optional<OffsetDateTime> getSince(); OffsetDateTime getTransactionTime(); Optional<UUID> getAggregatorID(); void setAggregatorIDForTesting(UUID aggregatorID); Optional<OffsetDateTime> getUpdateTime(); Optional<OffsetDateTime> getSubmitTime(); Optional<OffsetDateTime> getStartTime(); Optional<OffsetDateTime> getCompleteTime(); void setCompleteTime(OffsetDateTime time); List<JobQueueBatchFile> getJobQueueBatchFiles(); Optional<JobQueueBatchFile> getJobQueueFile(ResourceType forResourceType); Optional<JobQueueBatchFile> getJobQueueFile(String fileName); synchronized Optional<JobQueueBatchFile> getJobQueueFileLatest(ResourceType forResourceType); synchronized JobQueueBatchFile addJobQueueFile(ResourceType resourceType, int sequence, int batchSize); void setRunningStatus(UUID aggregatorID); Optional<String> fetchNextPatient(UUID aggregatorID); void setPausedStatus(UUID aggregatorID); void setCompletedStatus(UUID aggregatorID); void setFailedStatus(UUID aggregatorID); void restartBatch(); void setPriority(Integer priority); void setUpdateTime(); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); static final List<ResourceType> validResourceTypes; }### Answer:
@Test void testSetCompletedStatus() { final var job = Mockito.spy(createJobQueueBatch()); job.status = JobStatus.RUNNING; job.patientIndex = 2; job.setCompletedStatus(aggregatorID); assertEquals(JobStatus.COMPLETED, job.getStatus()); assertFalse(job.getAggregatorID().isPresent()); assertNotNull(job.getCompleteTime()); assertNull(job.patientIndex); Mockito.verify(job).verifyAggregatorID(aggregatorID); }
@Test void testSetFinishedStatus_InvalidRunningStatus() { final var job = Mockito.spy(createJobQueueBatch()); job.status = JobStatus.QUEUED; try { job.setCompletedStatus(aggregatorID); Assertions.fail(); } catch (JobQueueFailure e) { assertTrue(e.getMessage().contains("Cannot complete. JobStatus")); } }
@Test void testSetFinishedStatus_NotDoneProcessing() { final var job = Mockito.spy(createJobQueueBatch()); job.status = JobStatus.RUNNING; try { job.setCompletedStatus(aggregatorID); Assertions.fail(); } catch (JobQueueFailure e) { assertTrue(e.getMessage().contains("Cannot complete. Job processing not finished")); } }