### Question:
HashRateCalculator { public BigInteger calculateNetHashRate(Duration period) { return calculateHashRate(b -> true, period); } HashRateCalculator(BlockStore blockStore, UscCustomCache<Keccak256, BlockHeaderElement> headerCache); void start(); void stop(); abstract BigInteger calculateNodeHashRate(Duration duration); BigInteger calculateNetHashRate(Duration period);  }### Answer:
@Test public void calculateNetHashRate() { long ts = System.currentTimeMillis() / 1000L; Mockito.when(blockHeader.getTimestamp()).thenReturn(ts); Mockito.when(blockHeader.getCoinbase()) .thenReturn(NOT_MY_COINBASE) .thenReturn(FAKE_COINBASE) .thenReturn(FAKE_COINBASE) .thenReturn(NOT_MY_COINBASE); Mockito.when(block.getCumulativeDifficulty()).thenReturn(TEST_DIFFICULTY); HashRateCalculator hashRateCalculator = new HashRateCalculatorMining(blockStore, new UscCustomCache<>(1000L), FAKE_COINBASE); BigInteger hashRate = hashRateCalculator.calculateNetHashRate(Duration.ofHours(1)); Assert.assertEquals(hashRate, new BigInteger("+4")); }
@Test public void calculateNetHashRateOldBlock() { long ts = System.currentTimeMillis() / 1000L; Mockito.when(blockHeader.getTimestamp()) .thenReturn(ts - 10000L); Mockito.when(blockHeader.getCoinbase()).thenReturn(FAKE_COINBASE); Mockito.when(block.getCumulativeDifficulty()).thenReturn(TEST_DIFFICULTY); HashRateCalculator hashRateCalculator = new HashRateCalculatorMining(blockStore, new UscCustomCache<>(1000L), FAKE_COINBASE); BigInteger hashRate = hashRateCalculator.calculateNetHashRate(Duration.ofHours(1)); Assert.assertEquals(hashRate, BigInteger.ZERO); }