### Question:
BlockChainManagerImpl implements BlockChainManager<T> { @Override public void addBlock(ConsensusBlock<T> nextBlock) { try { lock.lock(); for (Transaction tx : nextBlock.getBody().getTransactionList()) { if (receiptStore.contains(tx.getHash().toString()) && receiptStore.get(tx.getHash().toString()).getStatus() != ExecuteStatus.ERROR) { addTransaction(tx); } } batchTxs(nextBlock); this.blockStore.addBlock(nextBlock); setLastConfirmedBlock(nextBlock); } finally { lock.unlock(); } } BlockChainManagerImpl(BlockChainStore blockChainStore); @Override void initGenesis(Block genesisBlock); @Override void loadTransaction(); @Override int verify(Transaction transaction); @Override int verify(ConsensusBlock<T> block); @Override void addBlock(ConsensusBlock<T> nextBlock); @Override void batchTxs(ConsensusBlock<T> block); @Override void addTransaction(Transaction tx); @Override void flushUnconfirmedTxs(Set<Sha3Hash> keys); @Override void updateTxCache(Block block); @Override ConsensusBlock<T> getLastConfirmedBlock(); @Override ConsensusBlock<T> getBlockByHash(Sha3Hash hash); @Override ConsensusBlock<T> getBlockByIndex(long index); @Override Transaction getTxByHash(Sha3Hash hash); @Override Collection<Transaction> getRecentTxs(); @Override List<Transaction> getUnconfirmedTxs(); @Override List<Transaction> getUnconfirmedTxsWithLimit(long limit); @Override int getUnconfirmedTxsSize(); @Override Receipt getReceipt(String key); @Override Sha3Hash getLastHash(); @Override long getLastIndex(); @Override long countOfBlocks(); @Override boolean containsBlockHash(Sha3Hash blockHash); @Override boolean containsTxHash(Sha3Hash txHash); @Override boolean contains(Block block); @Override boolean contains(Transaction transaction); @Override void close();  }### Answer:
@Test public void addBlockTest() { ConsensusBlock<PbftProto.PbftBlock> genesisBlock = BlockChainTestUtils.genesisBlock(); assertEquals(32000, blockChainManager.verify(genesisBlock)); blockChainManager.addBlock(genesisBlock); assertEquals(0, blockChainManager.getLastIndex()); assertEquals(blockChainManager.getLastHash(), genesisBlock.getBlock().getHash()); assertEquals(blockChainManager.getLastConfirmedBlock(), genesisBlock); assertEquals(0, blockChainManager.getUnconfirmedTxs().size()); assertEquals(1, blockChainManager.countOfBlocks()); ConsensusBlock<PbftProto.PbftBlock> block = generateBlockWithTxs(true); assertEquals(32000, blockChainManager.verify(block)); blockChainManager.addBlock(block); assertTrue(blockChainManager.contains(block)); assertEquals(block, blockChainManager.getBlockByHash(block.getHash())); assertEquals(block, blockChainManager.getBlockByIndex(1)); assertEquals(block, blockChainManager.getLastConfirmedBlock()); assertEquals(block.getHash(),blockChainManager.getLastHash()); assertEquals(2, blockChainManager.countOfBlocks()); assertEquals(0, blockChainManager.getUnconfirmedTxs().size()); assertEquals(10, blockChainManager.getRecentTxs().size()); assertEquals(32004, blockChainManager.verify(block)); block.getBlock().getBody().getTransactionList().add(BlockChainTestUtils.createTransferTx()); assertEquals(32004, blockChainManager.verify(block)); ConsensusBlock<PbftProto.PbftBlock> blockWithInvalidTx = generateBlockWithTxs(false); assertEquals(32000, blockChainManager.verify(blockWithInvalidTx)); blockChainManager.addBlock(blockWithInvalidTx); assertEquals(3, blockChainManager.countOfBlocks()); assertEquals(20, blockChainManager.getRecentTxs().size()); }