@Test public void shouldConvertViewModelsToRnrFormList() throws Exception { InventoryViewModel inventoryViewModel1 = buildInventoryViewModel("P1", "12"); inventoryViewModel1.setChecked(true); InventoryViewModel inventoryViewModel2 = buildInventoryViewModel("P2", "34"); inventoryViewModel2.setChecked(true); when(productRepository.getByCode("P1")).thenReturn(new ProductBuilder().setCode("P1").setIsActive(true).setIsArchived(false).build()); when(productRepository.getByCode("P2")).thenReturn(new ProductBuilder().setCode("P2").setIsActive(true).setIsArchived(true).build()); presenter.getInventoryViewModelList().addAll(newArrayList(inventoryViewModel1, inventoryViewModel2)); TestSubscriber<ArrayList<RnrFormItem>> subscriber = new TestSubscriber<>(); Observable observable = presenter.convertViewModelsToRnrFormItems(); observable.subscribe(subscriber); subscriber.awaitTerminalEvent(); subscriber.assertNoErrors(); assertThat(subscriber.getOnNextEvents().get(0).size(), is(2)); assertThat(subscriber.getOnNextEvents().get(0).get(0).getProduct().getCode(), is("P1")); assertThat(subscriber.getOnNextEvents().get(0).get(0).getRequestAmount(), is(12L)); assertThat(subscriber.getOnNextEvents().get(0).get(1).getProduct().getCode(), is("P2")); assertThat(subscriber.getOnNextEvents().get(0).get(1).getRequestAmount(), is(34L)); }
public Observable<ArrayList<RnrFormItem>> convertViewModelsToRnrFormItems() { return Observable.just(new ArrayList<>( FluentIterable.from(inventoryViewModelList) .filter(viewModel -> viewModel.isChecked()).transform(inventoryViewModel -> { RnrFormItem rnrFormItem = new RnrFormItem(); try { Product product = productRepository.getByCode(inventoryViewModel.getFnm()); rnrFormItem.setProduct(product); rnrFormItem.setRequestAmount(Long.valueOf(((AddDrugsToViaInventoryViewModel) inventoryViewModel).getQuantity())); } catch (LMISException e) { new LMISException(e, "AddDrugsToVIAPresenter,convertViewModelsToRnrFormItems").reportToFabric(); } return rnrFormItem; }).toList())) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()); }
AddDrugsToVIAPresenter extends Presenter { public Observable<ArrayList<RnrFormItem>> convertViewModelsToRnrFormItems() { return Observable.just(new ArrayList<>( FluentIterable.from(inventoryViewModelList) .filter(viewModel -> viewModel.isChecked()).transform(inventoryViewModel -> { RnrFormItem rnrFormItem = new RnrFormItem(); try { Product product = productRepository.getByCode(inventoryViewModel.getFnm()); rnrFormItem.setProduct(product); rnrFormItem.setRequestAmount(Long.valueOf(((AddDrugsToViaInventoryViewModel) inventoryViewModel).getQuantity())); } catch (LMISException e) { new LMISException(e, "AddDrugsToVIAPresenter,convertViewModelsToRnrFormItems").reportToFabric(); } return rnrFormItem; }).toList())) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()); } }
AddDrugsToVIAPresenter extends Presenter { public Observable<ArrayList<RnrFormItem>> convertViewModelsToRnrFormItems() { return Observable.just(new ArrayList<>( FluentIterable.from(inventoryViewModelList) .filter(viewModel -> viewModel.isChecked()).transform(inventoryViewModel -> { RnrFormItem rnrFormItem = new RnrFormItem(); try { Product product = productRepository.getByCode(inventoryViewModel.getFnm()); rnrFormItem.setProduct(product); rnrFormItem.setRequestAmount(Long.valueOf(((AddDrugsToViaInventoryViewModel) inventoryViewModel).getQuantity())); } catch (LMISException e) { new LMISException(e, "AddDrugsToVIAPresenter,convertViewModelsToRnrFormItems").reportToFabric(); } return rnrFormItem; }).toList())) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()); } AddDrugsToVIAPresenter(); }
AddDrugsToVIAPresenter extends Presenter { public Observable<ArrayList<RnrFormItem>> convertViewModelsToRnrFormItems() { return Observable.just(new ArrayList<>( FluentIterable.from(inventoryViewModelList) .filter(viewModel -> viewModel.isChecked()).transform(inventoryViewModel -> { RnrFormItem rnrFormItem = new RnrFormItem(); try { Product product = productRepository.getByCode(inventoryViewModel.getFnm()); rnrFormItem.setProduct(product); rnrFormItem.setRequestAmount(Long.valueOf(((AddDrugsToViaInventoryViewModel) inventoryViewModel).getQuantity())); } catch (LMISException e) { new LMISException(e, "AddDrugsToVIAPresenter,convertViewModelsToRnrFormItems").reportToFabric(); } return rnrFormItem; }).toList())) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()); } AddDrugsToVIAPresenter(); @Override void attachView(BaseView v); Observable<Void> loadActiveProductsNotInVIAForm(final List<String> existingProducts); Observable<ArrayList<RnrFormItem>> convertViewModelsToRnrFormItems(); }
AddDrugsToVIAPresenter extends Presenter { public Observable<ArrayList<RnrFormItem>> convertViewModelsToRnrFormItems() { return Observable.just(new ArrayList<>( FluentIterable.from(inventoryViewModelList) .filter(viewModel -> viewModel.isChecked()).transform(inventoryViewModel -> { RnrFormItem rnrFormItem = new RnrFormItem(); try { Product product = productRepository.getByCode(inventoryViewModel.getFnm()); rnrFormItem.setProduct(product); rnrFormItem.setRequestAmount(Long.valueOf(((AddDrugsToViaInventoryViewModel) inventoryViewModel).getQuantity())); } catch (LMISException e) { new LMISException(e, "AddDrugsToVIAPresenter,convertViewModelsToRnrFormItems").reportToFabric(); } return rnrFormItem; }).toList())) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()); } AddDrugsToVIAPresenter(); @Override void attachView(BaseView v); Observable<Void> loadActiveProductsNotInVIAForm(final List<String> existingProducts); Observable<ArrayList<RnrFormItem>> convertViewModelsToRnrFormItems();  }