DiscoveredList extends ObservedList<T> implements AdvertisementFoundListener, AdvertisementLostListener { @Override public void handleLostAdvertisement(Advertisement advertisement) { final Id id = Id.fromAdId(advertisement.getId()); mHandler.post( new Runnable() { @Override public void run() { if (mRejects.contains(id)) { return; } int i = findIndexWithId(id); if (i == NOT_FOUND) { return; } remove(i); } }); } DiscoveredList(AdConverter<T> converter, IdSet rejects, Handler handler); @Override void handleFoundAdvertisement(Advertisement advertisement); @Override void handleLostAdvertisement(Advertisement advertisement); void dropAll();  }
@Test public void handleUnrecognizedLost() throws Exception { mList.setObserver(mObserver); mList.handleLostAdvertisement(mAdvertisement); verify(mHandler).post(mRunnable.capture()); mRunnable.getValue().run(); assertEquals(0, mList.size()); verifyZeroInteractions(mHandler); verifyZeroInteractions(mObserver); }
@Test public void handleSelfLost() throws Exception { mList.setObserver(mObserver); when(mRejects.contains(ID0)).thenReturn(true); mList.handleLostAdvertisement(mAdvertisement); verify(mHandler).post(mRunnable.capture()); mRunnable.getValue().run(); assertEquals(0, mList.size()); verifyZeroInteractions(mHandler); verifyZeroInteractions(mObserver); }
@Test public void handleNormalLost() throws Exception { mList.setObserver(mObserver); mList.add(0, THING0); verify(mObserver).notifyItemInserted(0); assertEquals(1, mList.size()); mList.handleLostAdvertisement(mAdvertisement); verify(mHandler).post(mRunnable.capture()); mRunnable.getValue().run(); assertEquals(0, mList.size()); verify(mObserver).notifyItemRemoved(0); }