ALRequisitionPresenter extends BaseRequisitionPresenter { @Override protected Observable<RnRForm> getRnrFormObservable(long formId) { return Observable.create(new Observable.OnSubscribe<RnRForm>() { @Override public void call(Subscriber<? super RnRForm> subscriber) { try { rnRForm = getRnrForm(formId); subscriber.onNext(rnRForm); subscriber.onCompleted(); } catch (LMISException e) { new LMISException(e, "ALRequisitionPresenter,getRnrFormObservable").reportToFabric(); subscriber.onError(e); } } }).observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.io()); }  @Override void attachView(BaseView baseView); @Override void loadData(long formId, Date periodEndDate); @Override void updateUIAfterSubmit(); @Override void updateFormUI(); Observable<Void> getSaveFormObservable(); boolean isComplete(); void setViewModels(); public ALReportViewModel alReportViewModel; }
@Test public void shouldInitALViewModel() throws LMISException { RnRForm rnRForm = mock(RnRForm.class); when(mockALRepository.queryRnRForm(1L)).thenReturn(rnRForm); when(rnRForm.getRnrItems(Product.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(Product.IsKit.Yes)).thenReturn(rnrFormItems); TestSubscriber<RnRForm> testSubscriber = new TestSubscriber<>(); alRequisitionPresenter.getRnrFormObservable(1L).subscribe(testSubscriber); testSubscriber.awaitTerminalEvent(); testSubscriber.assertNoErrors(); }