DiscoveredList extends ObservedList<T> implements AdvertisementFoundListener, AdvertisementLostListener { @Override public void handleFoundAdvertisement(Advertisement advertisement) { final Id id = Id.fromAdId(advertisement.getId()); if (mRejects.contains(id)) { return; } final T item = mConverter.make(advertisement); if (item == null) { return; } mHandler.post( new Runnable() { @Override public void run() { push(item); } }); } DiscoveredList(AdConverter<T> converter, IdSet rejects, Handler handler); @Override void handleFoundAdvertisement(Advertisement advertisement); @Override void handleLostAdvertisement(Advertisement advertisement); void dropAll();  }
@Test public void handleNormalFound() throws Exception { mList.setObserver(mObserver); when(mConverter.make(mAdvertisement)).thenReturn(THING0); mList.handleFoundAdvertisement(mAdvertisement); verify(mHandler).post(mRunnable.capture()); mRunnable.getValue().run(); assertEquals(1, mList.size()); assertEquals(THING0, mList.get(0)); verify(mObserver).notifyItemInserted(0); }
@Test public void handleSelfFound() throws Exception { mList.setObserver(mObserver); when(mRejects.contains(ID0)).thenReturn(true); mList.handleFoundAdvertisement(mAdvertisement); verifyZeroInteractions(mHandler); verifyZeroInteractions(mObserver); assertEquals(0, mList.size()); }