### Question:
DelfiDeliveryService implements DeliveryService { @Override public DeliveryResponse getResources(InputPayload inputPayload, MessageHeaders headers) { log.debug("Getting resources for following SRNs and headers : {}, {}", inputPayload, headers); String authorizationToken = extractHeaderByName(headers, OsduHeader.AUTHORIZATION); String partition = extractHeaderByName(headers, OsduHeader.PARTITION); authenticationService.checkAuthentication(authorizationToken, partition); Map<String, Future<ProcessingResult>> srnToFutureMap = inputPayload.getSrns().stream() .distinct() .collect(Collectors.toMap(Function.identity(), srn -> dataProcessingJob.process(srn, authorizationToken, partition))); List<ProcessingResult> results = srnToFutureMap.entrySet().stream() .map(this::getProcessingResult) .collect(Collectors.toList()); return resultDataConverter.convertProcessingResults(results); }  @Override DeliveryResponse getResources(InputPayload inputPayload, MessageHeaders headers);  }### Answer:
@Test public void shouldGetRecord() throws ExecutionException, InterruptedException { ProcessingResult result1 = new ProcessingResult(); ProcessingResult result2 = new ProcessingResult(); when(dataProcessingJob.process(eq(SRN_1), eq(AUTH), eq(PARTITION))) .thenReturn(processingResultCompletableFutureOne); when(dataProcessingJob.process(eq(SRN_2), eq(AUTH), eq(PARTITION))) .thenReturn(processingResultCompletableFutureTwo); when(processingResultCompletableFutureOne.get()).thenReturn(result1); when(processingResultCompletableFutureTwo.get()).thenReturn(result2); DeliveryResponse deliveryResponse = new DeliveryResponse(); when(resultDataConverter.convertProcessingResults(eq(Arrays.asList(result1, result2)))) .thenReturn(deliveryResponse); InputPayload inputPayload = new InputPayload(Arrays.asList(SRN_1, SRN_2), REGION_ID); Map<String, Object> map = new HashMap<>(); map.put(OsduHeader.AUTHORIZATION, AUTH); map.put(OsduHeader.PARTITION, PARTITION); MessageHeaders headers = new MessageHeaders(map); DeliveryResponse response = delfiDeliveryService.getResources(inputPayload, headers); assertEquals(response, deliveryResponse); }
@Test public void shouldFailGetRecordWithErrorInJob() throws ExecutionException, InterruptedException { when(dataProcessingJob.process(any(), any(), any())) .thenReturn(processingResultCompletableFutureOne); when(processingResultCompletableFutureOne.get()) .thenThrow(new ExecutionException(new RuntimeException())); InputPayload inputPayload = new InputPayload(Collections.singletonList(SRN_1), REGION_ID); MessageHeaders headers = new MessageHeaders(new HashMap<>()); Throwable thrown = catchThrowable( () -> delfiDeliveryService.getResources(inputPayload, headers)); Assertions.assertThat(thrown) .isInstanceOf(OsduException.class) .hasMessageContaining("Error execution srn -"); }