### Question:
LogFilter extends Filter { @Override public void newBlockReceived(Block b) { if (this.fromLatestBlock) { this.clearEvents(); onBlock(b); } else if (this.toLatestBlock) { onBlock(b); } } LogFilter(AddressesTopicsFilter addressesTopicsFilter, Blockchain blockchain, boolean fromLatestBlock, boolean toLatestBlock); @Override void newBlockReceived(Block b); @Override void newPendingTx(Transaction tx); static LogFilter fromFilterRequest(Web3.FilterRequest fr, Blockchain blockchain);  }### Answer:
@Test public void noEventsAfterEmptyBlock() { LogFilter filter = new LogFilter(null, null, false, false); Block block = new BlockGenerator().getBlock(1); filter.newBlockReceived(block); Object[] result = filter.getEvents(); Assert.assertNotNull(result); Assert.assertEquals(0, result.length); }
@Test public void eventAfterBlockWithEvent() { BlockChainImpl blockchain = new UscTestFactory().getBlockchain(); Web3ImplLogsTest.addEmptyBlockToBlockchain(blockchain); Block block = blockchain.getBestBlock(); AddressesTopicsFilter atfilter = new AddressesTopicsFilter(new UscAddress[0], null); LogFilter filter = new LogFilter(atfilter, blockchain, false, true); filter.newBlockReceived(block); Object[] result = filter.getEvents(); Assert.assertNotNull(result); Assert.assertEquals(1, result.length); }
@Test public void twoEventsAfterTwoBlocksWithEventAndToLatestBlock() { BlockChainImpl blockchain = new UscTestFactory().getBlockchain(); Web3ImplLogsTest.addEmptyBlockToBlockchain(blockchain); Block block = blockchain.getBestBlock(); AddressesTopicsFilter atfilter = new AddressesTopicsFilter(new UscAddress[0], null); LogFilter filter = new LogFilter(atfilter, blockchain, false, true); filter.newBlockReceived(block); filter.newBlockReceived(block); Object[] result = filter.getEvents(); Assert.assertNotNull(result); Assert.assertEquals(2, result.length); }
@Test public void onlyOneEventAfterTwoBlocksWithEventAndFromLatestBlock() { BlockChainImpl blockchain = new UscTestFactory().getBlockchain(); Web3ImplLogsTest.addEmptyBlockToBlockchain(blockchain); Block block = blockchain.getBestBlock(); AddressesTopicsFilter atfilter = new AddressesTopicsFilter(new UscAddress[0], null); LogFilter filter = new LogFilter(atfilter, blockchain, true, true); filter.newBlockReceived(block); filter.newBlockReceived(block); Object[] result = filter.getEvents(); Assert.assertNotNull(result); Assert.assertEquals(1, result.length); }