TransactionsPool { public void addBlock(Block block) { Util.check(block != null, "block != null"); if (BlockUtil.isEmptyBlock(block)) { return; } Object dummyObject = new Object(); synchronized (locker) { Collection<String> hashes = BlockUtil.getTransactionsHashesAsString(block); for (String hash : hashes) { lastTransactions.put(hash, dummyObject); } transactions.removeAll(hashes); } }  List<String> getTransactions(); boolean addTransaction(String transactionHash); boolean checkExists(String transactionHash); void addBlock(Block block);  }
@Test(expected = IllegalArgumentException.class) public void testAddShouldThrowException() { TransactionsPool transactionsProcessed = new TransactionsPool(); transactionsProcessed.addBlock(null); }
@Test public void testAddEmptyBlock() { TransactionsPool transactionsProcessed = new TransactionsPool(); Block emptyBlock = new Block(); transactionsProcessed.addBlock(emptyBlock); TestCase.assertEquals(0, transactionsProcessed.lastTransactions.size()); }
@Test public void testAddBlock() { TransactionsPool transactionsProcessed = new TransactionsPool(); Block block = new Block(); for (int i = 0; i < 10; i++) { BlockUtil.addTransactionInBlock(block, new byte[]{(byte) i}); } transactionsProcessed.addBlock(block); TestCase.assertEquals(10, transactionsProcessed.lastTransactions.size()); TestCase.assertTrue(transactionsProcessed.checkExists(Util.getDataEncoded64(new byte[]{(byte) 3}))); TestCase.assertFalse(transactionsProcessed.checkExists(Util.getDataEncoded64(new byte[]{(byte) 11}))); }