ProductPresenter extends Presenter { public Observable<List<RegimeProductViewModel>> loadRegimeProducts(Regimen.RegimeType type) { return Observable.create((Observable.OnSubscribe<List<RegimeProductViewModel>>) subscriber -> { try { List<RegimeShortCode> regimeShortCodes = regimenRepository.listRegimeShortCode(type); List<RegimeProductViewModel> regimeProductViewModels = new ArrayList<>(); for (RegimeShortCode item : regimeShortCodes) { RegimeProductViewModel regimeProductViewModel = new RegimeProductViewModel(item.getShortCode()); regimeProductViewModels.add(regimeProductViewModel); } subscriber.onNext(regimeProductViewModels); subscriber.onCompleted(); } catch (LMISException e) { new LMISException(e, "ProductPresenter.loadRegimeProducts").reportToFabric(); subscriber.onError(e); } }).observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.io()); }  @Override void attachView(BaseView v); Observable<List<RegimeProductViewModel>> loadRegimeProducts(Regimen.RegimeType type); Observable<Regimen> saveRegimes(RegimeProductViewModel viewModel, final Regimen.RegimeType regimeType); Observable<List<InventoryViewModel>> loadEmergencyProducts();  }
@Test public void shouldLoadRegimeProducts() throws Exception { RegimeShortCode regimeShortCode = new RegimeShortCode(); regimeShortCode.setCode("code"); regimeShortCode.setShortCode("3TC 150mg"); when(regimenRepository.listRegimeShortCode(Regimen.RegimeType.Adults)).thenReturn(newArrayList(regimeShortCode)); Product product = new Product(); product.setPrimaryName("PrimaryName"); when(productRepository.getByCode("code")).thenReturn(product); TestSubscriber<List<RegimeProductViewModel>> subscriber = new TestSubscriber<>(); presenter.loadRegimeProducts(Regimen.RegimeType.Adults).subscribe(subscriber); subscriber.awaitTerminalEvent(); subscriber.assertNoErrors(); assertThat(subscriber.getOnNextEvents().get(0).size(), is(1)); assertThat(subscriber.getOnNextEvents().get(0).get(0).getShortCode(), is("3TC 150mg")); }