@Test public void testRemovePeer() throws Exception { HashMap<PeerProperties, Timestamp> mDiscoveredPeers = new HashMap<>(); mDiscoveredPeers.put(mMockPeerProperties, new Timestamp(1000L)); Field mDiscoveredPeersField = mPeerModel.getClass().getDeclaredField("mDiscoveredPeers"); mDiscoveredPeersField.setAccessible(true); mDiscoveredPeersField.set(mPeerModel, mDiscoveredPeers); PeerProperties pp = mPeerModel.removePeer(mMockPeerProperties); assertThat("The proper peer properties instance is returned", pp, is(mMockPeerProperties)); assertThat("The given peer properties id removedfrom the collection", mDiscoveredPeers.size(), is(0)); pp = mPeerModel.removePeer(mMockPeerProperties); assertThat("The null value is returned if the given peer properties not found", pp, is(nullValue())); pp = mPeerModel.removePeer(null); assertThat("Is null when the given peer properties is null", pp, is(nullValue())); }
public synchronized PeerProperties removePeer(PeerProperties peerPropertiesToRemove) { PeerProperties oldPeerProperties = null; if (peerPropertiesToRemove != null) { Iterator iterator = mDiscoveredPeers.entrySet().iterator(); while (iterator.hasNext()) { HashMap.Entry entry = (HashMap.Entry) iterator.next(); if (entry != null) { PeerProperties peerProperties = (PeerProperties) entry.getKey(); if (peerProperties.equals(peerPropertiesToRemove)) { oldPeerProperties = peerProperties; iterator.remove(); break; } } } } return oldPeerProperties; }
PeerModel { public synchronized PeerProperties removePeer(PeerProperties peerPropertiesToRemove) { PeerProperties oldPeerProperties = null; if (peerPropertiesToRemove != null) { Iterator iterator = mDiscoveredPeers.entrySet().iterator(); while (iterator.hasNext()) { HashMap.Entry entry = (HashMap.Entry) iterator.next(); if (entry != null) { PeerProperties peerProperties = (PeerProperties) entry.getKey(); if (peerProperties.equals(peerPropertiesToRemove)) { oldPeerProperties = peerProperties; iterator.remove(); break; } } } } return oldPeerProperties; } }
PeerModel { public synchronized PeerProperties removePeer(PeerProperties peerPropertiesToRemove) { PeerProperties oldPeerProperties = null; if (peerPropertiesToRemove != null) { Iterator iterator = mDiscoveredPeers.entrySet().iterator(); while (iterator.hasNext()) { HashMap.Entry entry = (HashMap.Entry) iterator.next(); if (entry != null) { PeerProperties peerProperties = (PeerProperties) entry.getKey(); if (peerProperties.equals(peerPropertiesToRemove)) { oldPeerProperties = peerProperties; iterator.remove(); break; } } } } return oldPeerProperties; } PeerModel(Listener listener, DiscoveryManagerSettings settings); }
PeerModel { public synchronized PeerProperties removePeer(PeerProperties peerPropertiesToRemove) { PeerProperties oldPeerProperties = null; if (peerPropertiesToRemove != null) { Iterator iterator = mDiscoveredPeers.entrySet().iterator(); while (iterator.hasNext()) { HashMap.Entry entry = (HashMap.Entry) iterator.next(); if (entry != null) { PeerProperties peerProperties = (PeerProperties) entry.getKey(); if (peerProperties.equals(peerPropertiesToRemove)) { oldPeerProperties = peerProperties; iterator.remove(); break; } } } } return oldPeerProperties; } PeerModel(Listener listener, DiscoveryManagerSettings settings); void addListener(Listener listener); void removeListener(Listener listener); void clear(); void onPeerExpirationTimeChanged(); synchronized PeerProperties getDiscoveredPeerByBluetoothMacAddress(final String bluetoothMacAddress); synchronized PeerProperties getDiscoveredPeerByDeviceAddress(final String deviceAddress); synchronized PeerProperties removePeer(PeerProperties peerPropertiesToRemove); void addOrUpdateDiscoveredPeer(PeerProperties peerPropertiesToAddOrUpdate); synchronized void checkListForExpiredPeers(); }
PeerModel { public synchronized PeerProperties removePeer(PeerProperties peerPropertiesToRemove) { PeerProperties oldPeerProperties = null; if (peerPropertiesToRemove != null) { Iterator iterator = mDiscoveredPeers.entrySet().iterator(); while (iterator.hasNext()) { HashMap.Entry entry = (HashMap.Entry) iterator.next(); if (entry != null) { PeerProperties peerProperties = (PeerProperties) entry.getKey(); if (peerProperties.equals(peerPropertiesToRemove)) { oldPeerProperties = peerProperties; iterator.remove(); break; } } } } return oldPeerProperties; } PeerModel(Listener listener, DiscoveryManagerSettings settings); void addListener(Listener listener); void removeListener(Listener listener); void clear(); void onPeerExpirationTimeChanged(); synchronized PeerProperties getDiscoveredPeerByBluetoothMacAddress(final String bluetoothMacAddress); synchronized PeerProperties getDiscoveredPeerByDeviceAddress(final String deviceAddress); synchronized PeerProperties removePeer(PeerProperties peerPropertiesToRemove); void addOrUpdateDiscoveredPeer(PeerProperties peerPropertiesToAddOrUpdate); synchronized void checkListForExpiredPeers();  }