### Question:
BlockBroadcaster { public void propagate(final Block block, final Difficulty totalDifficulty) { blockPropagatedSubscribers.forEach(listener -> listener.accept(block, totalDifficulty)); final NewBlockMessage newBlockMessage = NewBlockMessage.create(block, totalDifficulty); ethContext .getEthPeers() .streamAvailablePeers() .filter(ethPeer -> !ethPeer.hasSeenBlock(block.getHash())) .forEach( ethPeer -> { ethPeer.registerKnownBlock(block.getHash()); try { ethPeer.send(newBlockMessage); } catch (final PeerConnection.PeerNotConnected e) { LOG.trace("Failed to broadcast new block to peer", e); } }); } BlockBroadcaster(final EthContext ethContext); long subscribePropagateNewBlocks(final BlockPropagatedSubscriber callback); void unsubscribePropagateNewBlocks(final long id); void propagate(final Block block, final Difficulty totalDifficulty);  }### Answer:
@Test public void blockPropagationUnitTest() throws PeerConnection.PeerNotConnected { final EthPeer ethPeer = mock(EthPeer.class); final EthPeers ethPeers = mock(EthPeers.class); when(ethPeers.streamAvailablePeers()).thenReturn(Stream.of(ethPeer)); final EthContext ethContext = mock(EthContext.class); when(ethContext.getEthPeers()).thenReturn(ethPeers); final BlockBroadcaster blockBroadcaster = new BlockBroadcaster(ethContext); final Block block = generateBlock(); final NewBlockMessage newBlockMessage = NewBlockMessage.create(block, block.getHeader().getDifficulty()); blockBroadcaster.propagate(block, Difficulty.ZERO); verify(ethPeer, times(1)).send(newBlockMessage); }
@Test public void blockPropagationUnitTestSeenUnseen() throws PeerConnection.PeerNotConnected { final EthPeer ethPeer0 = mock(EthPeer.class); when(ethPeer0.hasSeenBlock(any())).thenReturn(true); final EthPeer ethPeer1 = mock(EthPeer.class); final EthPeers ethPeers = mock(EthPeers.class); when(ethPeers.streamAvailablePeers()).thenReturn(Stream.of(ethPeer0, ethPeer1)); final EthContext ethContext = mock(EthContext.class); when(ethContext.getEthPeers()).thenReturn(ethPeers); final BlockBroadcaster blockBroadcaster = new BlockBroadcaster(ethContext); final Block block = generateBlock(); final NewBlockMessage newBlockMessage = NewBlockMessage.create(block, block.getHeader().getDifficulty()); blockBroadcaster.propagate(block, Difficulty.ZERO); verify(ethPeer0, never()).send(newBlockMessage); verify(ethPeer1, times(1)).send(newBlockMessage); }