PeerModel { public void clear() { if (mCheckExpiredPeersTimer != null) { Log.i(TAG, "clear"); mCheckExpiredPeersTimer.cancel(); mCheckExpiredPeersTimer = null; } mDiscoveredPeers.clear(); } 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();  }
@Test public void testClear() throws Exception { Field mCheckExpiredPeersTimerField = mPeerModel.getClass().getDeclaredField("mCheckExpiredPeersTimer"); mCheckExpiredPeersTimerField.setAccessible(true); mCheckExpiredPeersTimerField.set(mPeerModel, mMockCheckExpiredPeersTimer); Field mDiscoveredPeersField = mPeerModel.getClass().getDeclaredField("mDiscoveredPeers"); mDiscoveredPeersField.setAccessible(true); mDiscoveredPeersField.set(mPeerModel, mMockMap); mPeerModel.clear(); verify(mMockMap, times(1)) .clear(); verify(mMockCheckExpiredPeersTimer, times(1)) .cancel(); assertThat("The timer for checking for expired peers is stopped", mCheckExpiredPeersTimerField.get(mPeerModel), is(nullValue())); }