### Question:
CheckpointHeaderFetcher { public boolean nextCheckpointEndsAtChainHead( final EthPeer peer, final BlockHeader previousCheckpointHeader) { if (finalCheckpointHeader.isPresent()) { return false; } final int skip = syncConfig.getDownloaderChainSegmentSize() - 1; final long peerEstimatedHeight = peer.chainState().getEstimatedHeight(); final long previousCheckpointNumber = previousCheckpointHeader.getNumber(); return previousCheckpointNumber + skip >= peerEstimatedHeight; } CheckpointHeaderFetcher(
      final SynchronizerConfiguration syncConfig,
      final ProtocolSchedule protocolSchedule,
      final EthContext ethContext,
      final Optional<BlockHeader> finalCheckpointHeader,
      final MetricsSystem metricsSystem); CompletableFuture<List<BlockHeader>> getNextCheckpointHeaders(
      final EthPeer peer, final BlockHeader previousCheckpointHeader); boolean nextCheckpointEndsAtChainHead(
      final EthPeer peer, final BlockHeader previousCheckpointHeader);  }### Answer:
@Test public void nextCheckpointShouldEndAtChainHeadWhenNextCheckpointHeaderIsAfterHead() { final long remoteChainHeight = blockchain.getChainHeadBlockNumber(); final CheckpointHeaderFetcher checkpointHeaderFetcher = createCheckpointHeaderFetcher(Optional.empty()); assertThat( checkpointHeaderFetcher.nextCheckpointEndsAtChainHead( respondingPeer.getEthPeer(), header(remoteChainHeight - SEGMENT_SIZE + 1))) .isTrue(); }
@Test public void nextCheckpointShouldNotEndAtChainHeadWhenAFinalCheckpointHeaderIsSpecified() { final long remoteChainHeight = blockchain.getChainHeadBlockNumber(); final CheckpointHeaderFetcher checkpointHeaderFetcher = createCheckpointHeaderFetcher(Optional.of(header(remoteChainHeight))); assertThat( checkpointHeaderFetcher.nextCheckpointEndsAtChainHead( respondingPeer.getEthPeer(), header(remoteChainHeight - SEGMENT_SIZE + 1))) .isFalse(); }