### Question:
VoteTallyUpdater { public VoteTally buildVoteTallyFromBlockchain(final Blockchain blockchain) { final long chainHeadBlockNumber = blockchain.getChainHeadBlockNumber(); final long epochBlockNumber = epochManager.getLastEpochBlock(chainHeadBlockNumber); LOG.info("Loading validator voting state starting from block {}", epochBlockNumber); final BlockHeader epochBlock = blockchain.getBlockHeader(epochBlockNumber).get(); final Collection<Address> initialValidators = blockInterface.validatorsInBlock(epochBlock); final VoteTally voteTally = new VoteTally(initialValidators); for (long blockNumber = epochBlockNumber + 1; blockNumber <= chainHeadBlockNumber; blockNumber++) { updateForBlock(blockchain.getBlockHeader(blockNumber).get(), voteTally); } return voteTally; } VoteTallyUpdater(final EpochManager epochManager, final BlockInterface blockInterface); VoteTally buildVoteTallyFromBlockchain(final Blockchain blockchain); void updateForBlock(final BlockHeader header, final VoteTally voteTally);  }### Answer:
@Test public void buildVoteTallyByExtractingValidatorsFromGenesisBlock() { when(serialiser.validatorsInBlock(any())).thenReturn(asList(subject, validator1)); final BlockHeaderTestFixture headerBuilder = new BlockHeaderTestFixture(); headerBuilder.number(0); final BlockHeader header = headerBuilder.buildHeader(); when(blockchain.getChainHeadBlockNumber()).thenReturn(EPOCH_LENGTH); when(blockchain.getBlockHeader(EPOCH_LENGTH)).thenReturn(Optional.of(header)); final VoteTally voteTally = updater.buildVoteTallyFromBlockchain(blockchain); assertThat(voteTally.getValidators()).containsExactly(subject, validator1); }
@Test public void buildVoteTallyByExtractingValidatorsFromEpochBlock() { when(serialiser.validatorsInBlock(any())).thenReturn(asList(subject, validator1)); final BlockHeaderTestFixture headerBuilder = new BlockHeaderTestFixture(); final BlockHeader header = headerBuilder.buildHeader(); when(blockchain.getChainHeadBlockNumber()).thenReturn(EPOCH_LENGTH); when(blockchain.getBlockHeader(EPOCH_LENGTH)).thenReturn(Optional.of(header)); final VoteTally voteTally = updater.buildVoteTallyFromBlockchain(blockchain); assertThat(voteTally.getValidators()).containsExactly(subject, validator1); }
@Test public void addVotesFromBlocksAfterMostRecentEpoch() { when(serialiser.validatorsInBlock(any())).thenReturn(asList(validator1)); when(serialiser.extractVoteFromHeader(any())) .thenReturn(Optional.of(new ValidatorVote(VoteType.ADD, proposerAddress, subject))); final BlockHeaderTestFixture headerBuilder = new BlockHeaderTestFixture(); headerBuilder.number(EPOCH_LENGTH); final BlockHeader epochHeader = headerBuilder.buildHeader(); headerBuilder.number(EPOCH_LENGTH + 1); final BlockHeader voteBlockHeader = headerBuilder.buildHeader(); when(blockchain.getChainHeadBlockNumber()).thenReturn(EPOCH_LENGTH + 1); when(blockchain.getBlockHeader(EPOCH_LENGTH)).thenReturn(Optional.of(epochHeader)); when(blockchain.getBlockHeader(EPOCH_LENGTH + 1)).thenReturn(Optional.of(voteBlockHeader)); final VoteTally voteTally = updater.buildVoteTallyFromBlockchain(blockchain); assertThat(voteTally.getValidators()).containsExactly(subject, validator1); }