### Question:
DecidingSyncState extends BaseSyncState { @Override public void newPeerStatus() { if (knownPeers.count() >= syncConfiguration.getExpectedPeers()) { tryStartSyncing(); } } DecidingSyncState(SyncConfiguration syncConfiguration, SyncEventsHandler syncEventsHandler, SyncInformation syncInformation, PeersInformation knownPeers); @Override void newPeerStatus(); @Override void tick(Duration duration);  }### Answer:
@Test public void startsSyncingWith5Peers() { SyncConfiguration syncConfiguration = SyncConfiguration.DEFAULT; SimpleSyncEventsHandler syncEventsHandler = new SimpleSyncEventsHandler(); SimpleSyncInformation syncInformation = new SimpleSyncInformation(); ChannelManager channelManager = UscMockFactory.getChannelManager(); PeersInformation knownPeers = new PeersInformation(syncInformation, channelManager, syncConfiguration); SyncState syncState = new DecidingSyncState(syncConfiguration, syncEventsHandler, syncInformation, knownPeers); Collection<Channel> peers = new ArrayList<>(); for (int i = 0; i < 5; i++) { Assert.assertFalse(syncEventsHandler.startSyncingWasCalled()); NodeID nodeID = new NodeID(HashUtil.randomPeerId()); Channel channel = mock(Channel.class); when(channel.getNodeId()).thenReturn(nodeID); peers.add(channel); when(channelManager.getActivePeers()).thenReturn(peers); knownPeers.registerPeer(nodeID).setStatus(StatusUtils.getFakeStatus()); syncState.newPeerStatus(); } Assert.assertTrue(syncEventsHandler.startSyncingWasCalled()); }
@Test public void startsSyncingWith5NonRepeatedPeers() { SyncConfiguration syncConfiguration = SyncConfiguration.DEFAULT; SimpleSyncEventsHandler syncEventsHandler = new SimpleSyncEventsHandler(); SimpleSyncInformation syncInformation = new SimpleSyncInformation(); ChannelManager channelManager = UscMockFactory.getChannelManager(); PeersInformation knownPeers = new PeersInformation(syncInformation, channelManager, syncConfiguration); SyncState syncState = new DecidingSyncState(syncConfiguration, syncEventsHandler, syncInformation, knownPeers); Collection<Channel> peers = new ArrayList<>(); NodeID peerToRepeat = new NodeID(HashUtil.randomPeerId()); Channel channel = mock(Channel.class); when(channel.getNodeId()).thenReturn(peerToRepeat); peers.add(channel); for (int i = 0; i < 10; i++) { Assert.assertFalse(syncEventsHandler.startSyncingWasCalled()); knownPeers.registerPeer(peerToRepeat).setStatus(StatusUtils.getFakeStatus()); syncState.newPeerStatus(); } for (int i = 0; i < 4; i++) { Assert.assertFalse(syncEventsHandler.startSyncingWasCalled()); NodeID nodeID = new NodeID(HashUtil.randomPeerId()); knownPeers.registerPeer(nodeID).setStatus(StatusUtils.getFakeStatus()); channel = mock(Channel.class); when(channel.getNodeId()).thenReturn(nodeID); peers.add(channel); when(channelManager.getActivePeers()).thenReturn(peers); syncState.newPeerStatus(); } Assert.assertTrue(syncEventsHandler.startSyncingWasCalled()); }