MainPresenter { @Nonnull Observable<List<BaseAdapterItem>> itemsObservable() { return itemsObservable; } MainPresenter(@Nonnull final PostsDao postsDao,
                         @Nonnull final MyCurrentLoggedInUserDao currentLoggedInUserDao,
                         @Nonnull Scheduler uiScheduler);   }
@Test public void testBeforeDownload_doNotPropagateItems() throws Exception { final TestSubscriber<List<BaseAdapterItem>> items = new TestSubscriber<>(); mainPresenter.itemsObservable().subscribe(items); assert_().that(items.getOnNextEvents()) .isEmpty(); items.assertNoErrors(); }
@Test public void testAfterDownloadEmptyArray_emptyItemsArrayIsPropagated() throws Exception { final TestSubscriber<List<BaseAdapterItem>> items = new TestSubscriber<>(); mainPresenter.itemsObservable().subscribe(items); postsSubject.onNext(sampleData()); scheduler.triggerActions(); assert_().that(items.getOnNextEvents()) .contains(ImmutableList.of()); items.assertNoErrors(); }
@Test public void testAfterDownload_itemsArePropagated() throws Exception { final TestSubscriber<List<BaseAdapterItem>> items = new TestSubscriber<>(); mainPresenter.itemsObservable().subscribe(items); postsSubject.onNext(ResponseOrError.fromData(new PostsResponse("", ImmutableList.of(new Post("123", "krowa")), null))); scheduler.triggerActions(); assert_().that(items.getOnNextEvents()).hasSize(1); assert_().that(items.getOnNextEvents().get(0)).hasSize(1); assert_().that(items.getOnNextEvents().get(0).get(0)) .isInstanceOf(MainPresenter.AdapterItem.class); final MainPresenter.AdapterItem firstItem = (MainPresenter.AdapterItem) items .getOnNextEvents().get(0).get(0); assert_().that(firstItem.text()).isEqualTo("krowa"); assert_().that(firstItem.id()).isEqualTo("123"); items.assertNoErrors(); }