### Question:
DelfiIngestionService implements IngestionService { @Override public List<Record> failRecords(List<Record> records, RequestContext requestContext) { return records.stream() .map(record -> failRecord(requestContext, record)) .collect(Collectors.toList()); }  @Override SignedFile uploadFile(ManifestFile file, String authorizationToken, String partition); @Override List<Record> failRecords(List<Record> records, RequestContext requestContext);  }### Answer:
@Test public void shouldMarkRecordsAsFailedAndSaveThem() { List<Record> records = Arrays.asList(getDelfiRecord(), getDelfiRecord(), getDelfiRecord()); RequestContext requestContext = RequestContext.builder() .authorizationToken(AUTHORIZATION_TOKEN) .partition(PARTITION) .build(); given(portalService.putRecord(any(Record.class), eq(AUTHORIZATION_TOKEN), eq(PARTITION))) .willAnswer(this::getFailRecordAnswer); List<Record> failedRecords = ingestionService.failRecords(records, requestContext); then(failedRecords) .hasSize(3) .extracting("data.osdu.ResourceLifecycleStatus", String.class) .containsOnly("srn:reference-data/ResourceLifecycleStatus:RESCINDED:"); InOrder inOrder = inOrder(portalService, storageService, delfiIngestionClient); inOrder.verify(portalService, times(3)) .putRecord(any(Record.class), eq(AUTHORIZATION_TOKEN), eq(PARTITION)); inOrder.verifyNoMoreInteractions(); }
@Test public void shouldFallThroughExceptionDuringFailingRecords() { List<Record> records = Arrays.asList(getDelfiRecord(), getDelfiRecord(), getDelfiRecord()); RequestContext requestContext = RequestContext.builder() .authorizationToken(AUTHORIZATION_TOKEN) .partition(PARTITION) .build(); given(portalService.putRecord(any(Record.class), eq(AUTHORIZATION_TOKEN), eq(PARTITION))) .willAnswer(this::getFailRecordAnswer) .willThrow(new OsduBadRequestException("bad request")); Throwable thrown = catchThrowable(() -> ingestionService.failRecords(records, requestContext)); then(thrown) .isInstanceOf(OsduBadRequestException.class) .hasMessage("bad request"); InOrder inOrder = inOrder(portalService, storageService, delfiIngestionClient); inOrder.verify(portalService, times(2)) .putRecord(any(Record.class), eq(AUTHORIZATION_TOKEN), eq(PARTITION)); inOrder.verifyNoMoreInteractions(); }