### Question:
CheckpointHeaderValidationStep implements Function<CheckpointRangeHeaders, Stream<BlockHeader>> { @Override public Stream<BlockHeader> apply(final CheckpointRangeHeaders checkpointRangeHeaders) { final BlockHeader rangeStart = checkpointRangeHeaders.getCheckpointRange().getStart(); final BlockHeader firstHeaderToImport = checkpointRangeHeaders.getFirstHeaderToImport(); if (isValid(rangeStart, firstHeaderToImport)) { return checkpointRangeHeaders.getHeadersToImport().stream(); } else { final String rangeEndDescription; if (checkpointRangeHeaders.getCheckpointRange().hasEnd()) { final BlockHeader rangeEnd = checkpointRangeHeaders.getCheckpointRange().getEnd(); rangeEndDescription = String.format("#%d (%s)", rangeEnd.getNumber(), rangeEnd.getBlockHash()); } else { rangeEndDescription = "chain head"; } final String errorMessage = String.format( "Invalid checkpoint headers. Headers downloaded between #%d (%s) and %s do not connect at #%d (%s)", rangeStart.getNumber(), rangeStart.getHash(), rangeEndDescription, firstHeaderToImport.getNumber(), firstHeaderToImport.getHash()); throw new InvalidBlockException( errorMessage, firstHeaderToImport.getNumber(), firstHeaderToImport.getHash()); } } CheckpointHeaderValidationStep(
      final ProtocolSchedule protocolSchedule,
      final ProtocolContext protocolContext,
      final ValidationPolicy validationPolicy); @Override Stream<BlockHeader> apply(final CheckpointRangeHeaders checkpointRangeHeaders);  }### Answer:
@Test public void shouldValidateFirstHeaderAgainstCheckpointStartHeader() { when(headerValidator.validateHeader( firstHeader, checkpointStart, protocolContext, DETACHED_ONLY)) .thenReturn(true); final Stream<BlockHeader> result = validationStep.apply(rangeHeaders); verify(protocolSchedule).getByBlockNumber(firstHeader.getNumber()); verify(validationPolicy).getValidationModeForNextBlock(); verify(headerValidator) .validateHeader(firstHeader, checkpointStart, protocolContext, DETACHED_ONLY); verifyNoMoreInteractions(headerValidator, validationPolicy); assertThat(result).containsExactlyElementsOf(rangeHeaders.getHeadersToImport()); }
@Test public void shouldThrowExceptionWhenValidationFails() { when(headerValidator.validateHeader( firstHeader, checkpointStart, protocolContext, DETACHED_ONLY)) .thenReturn(false); assertThatThrownBy(() -> validationStep.apply(rangeHeaders)) .isInstanceOf(InvalidBlockException.class) .hasMessageContaining( "Invalid checkpoint headers. Headers downloaded between #" + checkpointStart.getNumber() + " (" + checkpointStart.getHash() + ") and #" + checkpointEnd.getNumber() + " (" + checkpointEnd.getHash() + ") do not connect at #" + firstHeader.getNumber() + " (" + firstHeader.getHash() + ")"); }