### Question:
FastImportBlocksStep implements Consumer<List<BlockWithReceipts>> { @Override public void accept(final List<BlockWithReceipts> blocksWithReceipts) { for (final BlockWithReceipts blockWithReceipts : blocksWithReceipts) { if (!importBlock(blockWithReceipts)) { throw new InvalidBlockException( "Failed to import block", blockWithReceipts.getHeader().getNumber(), blockWithReceipts.getHash()); } } final long firstBlock = blocksWithReceipts.get(0).getNumber(); final long lastBlock = blocksWithReceipts.get(blocksWithReceipts.size() - 1).getNumber(); int peerCount = -1; if (ethContext != null && ethContext.getEthPeers().peerCount() >= 0) { peerCount = ethContext.getEthPeers().peerCount(); } LOG.info( "Completed importing chain segment {} to {}, Peers: {}", firstBlock, lastBlock, peerCount); } FastImportBlocksStep(
      final ProtocolSchedule protocolSchedule,
      final ProtocolContext protocolContext,
      final ValidationPolicy headerValidationPolicy,
      final ValidationPolicy ommerValidationPolicy,
      final EthContext ethContext); @Override void accept(final List<BlockWithReceipts> blocksWithReceipts);  }### Answer:
@Test public void shouldImportBlocks() { final List<Block> blocks = gen.blockSequence(5); final List<BlockWithReceipts> blocksWithReceipts = blocks.stream() .map(block -> new BlockWithReceipts(block, gen.receipts(block))) .collect(toList()); for (final BlockWithReceipts blockWithReceipts : blocksWithReceipts) { when(blockImporter.fastImportBlock( protocolContext, blockWithReceipts.getBlock(), blockWithReceipts.getReceipts(), FULL, LIGHT)) .thenReturn(true); } importBlocksStep.accept(blocksWithReceipts); for (final BlockWithReceipts blockWithReceipts : blocksWithReceipts) { verify(protocolSchedule).getByBlockNumber(blockWithReceipts.getNumber()); } verify(validationPolicy, times(blocks.size())).getValidationModeForNextBlock(); }
@Test public void shouldThrowExceptionWhenValidationFails() { final Block block = gen.block(); final BlockWithReceipts blockWithReceipts = new BlockWithReceipts(block, gen.receipts(block)); when(blockImporter.fastImportBlock( protocolContext, block, blockWithReceipts.getReceipts(), FULL, LIGHT)) .thenReturn(false); assertThatThrownBy(() -> importBlocksStep.accept(singletonList(blockWithReceipts))) .isInstanceOf(InvalidBlockException.class); }