VIARequisitionPresenter extends BaseRequisitionPresenter { @Override protected Observable<RnRForm> getRnrFormObservable(final long formId) { return Observable.create((Observable.OnSubscribe<RnRForm>) subscriber -> { try { RnRForm rnrForm = getRnrForm(formId); convertRnrToViewModel(rnrForm); subscriber.onNext(rnrForm); subscriber.onCompleted(); } catch (LMISException e) { new LMISException(e, "VIARequisitionPresenter.getRnrFormObservable").reportToFabric(); subscriber.onError(e); } }).observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.io()); } VIARequisitionPresenter(); @Override void loadData(long formId, Date periodEndDate); void loadEmergencyData(final List<StockCard> stockCards, final Date periodEndDate); @Override void attachView(BaseView baseView); void populateAdditionalDrugsViewModels(List<RnrFormItem> addedDrugInVIAs, Date periodBegin); void deleteRnRItemFromViewModel(final RnrFormItem rnrFormItem); @Override void updateUIAfterSubmit(); @Override void updateFormUI(); @Override void submitRequisition(); boolean processRequisition(String consultationNumbers); Observable<RnRForm> getSaveFormObservable(final String consultationNumbers); String getConsultationNumbers(); void setConsultationNumbers(String consultationNumbers); void createStockCardsOrUnarchiveAndAddToFormForAdditionalRnrItems(); Observable<Void> removeRnrItem(final RnrFormItem rnrFormItem);  }
@Test public void shouldInitViaKitsViewModel() throws Exception { RnRForm rnRForm = mock(RnRForm.class); when(mockRnrFormRepository.queryRnRForm(1L)).thenReturn(rnRForm); when(rnRForm.getRnrItems(IsKit.No)).thenReturn(new ArrayList<RnrFormItem>()); RnrFormItem rnrKitItem1 = new RnrFormItemBuilder() .setProduct(new ProductBuilder().setCode("26A01").build()) .setReceived(100) .setIssued((long) 50) .build(); RnrFormItem rnrKitItem2 = new RnrFormItemBuilder() .setProduct(new ProductBuilder().setCode("26A02").build()) .setReceived(300) .setIssued((long) 110) .build(); List<RnrFormItem> rnrFormItems = Lists.newArrayList(rnrKitItem1, rnrKitItem2); when(rnRForm.getRnrItems(IsKit.Yes)).thenReturn(rnrFormItems); TestSubscriber<RnRForm> testSubscriber = new TestSubscriber<>(); presenter.getRnrFormObservable(1L).subscribe(testSubscriber); testSubscriber.awaitTerminalEvent(); testSubscriber.assertNoErrors(); assertEquals("50", presenter.getViaKitsViewModel().getKitsOpenedHF()); assertEquals("100", presenter.getViaKitsViewModel().getKitsReceivedHF()); assertEquals("110", presenter.getViaKitsViewModel().getKitsOpenedCHW()); assertEquals("300", presenter.getViaKitsViewModel().getKitsReceivedCHW()); }