### Question:
DataService { public Resource retrieveData(UUID organizationId, UUID providerId, List<String> patientIds, ResourceType... resourceTypes) { return retrieveData(organizationId, providerId, patientIds, OffsetDateTime.now(ZoneOffset.UTC), resourceTypes); } @Inject  DataService(IJobQueue queue, FhirContext fhirContext, @ExportPath String exportPath, @JobTimeout  int jobTimeoutInSeconds); Resource retrieveData(UUID organizationId, UUID providerId, List<String> patientIds, ResourceType... resourceTypes); Resource retrieveData(UUID organizationID,
                                 UUID providerID,
                                 List<String> patientIDs,
                                 OffsetDateTime transactionTime,
                                 ResourceType... resourceTypes);  }### Answer:
@Test public void whenGetJobBatchesThrowsException() { UUID orgID = UUID.randomUUID(); UUID providerID = UUID.randomUUID(); UUID patientID = UUID.randomUUID(); ResourceType resourceType = ResourceType.ExplanationOfBenefit; Mockito.doThrow(new RuntimeException("error")).when(queue).getJobBatches(Mockito.any(UUID.class)); Assertions.assertThrows(DataRetrievalException.class, () -> { dataService.retrieveData(orgID, providerID, Collections.singletonList(patientID.toString()), resourceType); }); }
@Test public void whenGetJobBatchesReturnsFailedJob() throws IllegalAccessException { UUID orgID = UUID.randomUUID(); UUID providerID = UUID.randomUUID(); UUID patientID = UUID.randomUUID(); ResourceType resourceType = ResourceType.ExplanationOfBenefit; workJob(true, resourceType); Assertions.assertThrows(DataRetrievalException.class, () -> { dataService.retrieveData(orgID, providerID, Collections.singletonList(patientID.toString()), resourceType); }); }
@Test public void whenGetJobBatchesReturnsCompletedJobWithResourceType() throws IllegalAccessException { UUID orgID = UUID.randomUUID(); UUID providerID = UUID.randomUUID(); UUID patientID = UUID.randomUUID(); ResourceType resourceType = ResourceType.ExplanationOfBenefit; workJob(false, resourceType); Resource resource = dataService.retrieveData(orgID, providerID, Collections.singletonList(patientID.toString()), resourceType); Assertions.assertTrue(resource instanceof Bundle); }
@Test public void whenGetJobBatchesReturnsCompletedJobWithOperationOutcome() throws IllegalAccessException { UUID orgID = UUID.randomUUID(); UUID providerID = UUID.randomUUID(); UUID patientID = UUID.randomUUID(); ResourceType resourceType = ResourceType.ExplanationOfBenefit; workJob(false, ResourceType.OperationOutcome); Resource resource = dataService.retrieveData(orgID, providerID, Collections.singletonList(patientID.toString()), resourceType); Assertions.assertTrue(resource instanceof OperationOutcome); }
@Test public void whenPassingInNoResourceTypes() throws IllegalAccessException { UUID orgID = UUID.randomUUID(); UUID providerID = UUID.randomUUID(); UUID patientID = UUID.randomUUID(); workJob(false, ResourceType.ExplanationOfBenefit); Assertions.assertThrows(DataRetrievalException.class, () -> { dataService.retrieveData(orgID, providerID, Collections.singletonList(patientID.toString())); }); }