@Test public void shouldThrowAnExceptionWhenFindForPeriodFails() throws InvocationTargetException, NoSuchMethodException, LMISException, IllegalAccessException { doThrow(LMISException.class).when(patientDataService).findForPeriod(period.getBegin(), period.getEnd()); Observable<List<ImplementationReportViewModel>> observable = malariaDataReportFormPresenter.getImplementationViewModelsForCurrentMalariaProgram(period); observable.subscribe(listImplementationViewModelSubscriber); listImplementationViewModelSubscriber.awaitTerminalEvent(); listImplementationViewModelSubscriber.assertError(LMISException.class); }
public Observable<List<ImplementationReportViewModel>> getImplementationViewModelsForCurrentMalariaProgram(final Period period) { this.period = period; return Observable.create((Observable.OnSubscribe<List<ImplementationReportViewModel>>) subscriber -> { try { malariaProgram = patientDataService.findForPeriod(period.getBegin(), period.getEnd()); MalariaDataReportViewModel malariaDataReportViewModel = reportViewModelMapper.Map(malariaProgram); ImplementationReportViewModel usImplementationReportViewModel = malariaDataReportViewModel.getUsImplementationReportViewModel(); if (malariaProgram != null) { createdBy = malariaProgram.getCreatedBy(); status = malariaProgram.getStatus(); } else { createdBy = ""; status = ViaReportStatus.MISSING; List<Long> malariaProductsStockHand = patientDataService.getMalariaProductsStockHand(); usImplementationReportViewModel.setExistingStock(malariaProductsStockHand); } viewModels.add(usImplementationReportViewModel); viewModels.add(malariaDataReportViewModel.getApeImplementationReportViewModel()); viewModels.add(generateTotalViewModel(viewModels.get(0), viewModels.get(1))); subscriber.onNext(viewModels); subscriber.onCompleted(); } catch (Exception e) { new LMISException(e, "MalariaData:getImple").reportToFabric(); subscriber.onError(e); } }).observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.io()); }
MalariaDataReportFormPresenter extends BaseReportPresenter { public Observable<List<ImplementationReportViewModel>> getImplementationViewModelsForCurrentMalariaProgram(final Period period) { this.period = period; return Observable.create((Observable.OnSubscribe<List<ImplementationReportViewModel>>) subscriber -> { try { malariaProgram = patientDataService.findForPeriod(period.getBegin(), period.getEnd()); MalariaDataReportViewModel malariaDataReportViewModel = reportViewModelMapper.Map(malariaProgram); ImplementationReportViewModel usImplementationReportViewModel = malariaDataReportViewModel.getUsImplementationReportViewModel(); if (malariaProgram != null) { createdBy = malariaProgram.getCreatedBy(); status = malariaProgram.getStatus(); } else { createdBy = ""; status = ViaReportStatus.MISSING; List<Long> malariaProductsStockHand = patientDataService.getMalariaProductsStockHand(); usImplementationReportViewModel.setExistingStock(malariaProductsStockHand); } viewModels.add(usImplementationReportViewModel); viewModels.add(malariaDataReportViewModel.getApeImplementationReportViewModel()); viewModels.add(generateTotalViewModel(viewModels.get(0), viewModels.get(1))); subscriber.onNext(viewModels); subscriber.onCompleted(); } catch (Exception e) { new LMISException(e, "MalariaData:getImple").reportToFabric(); subscriber.onError(e); } }).observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.io()); } }
MalariaDataReportFormPresenter extends BaseReportPresenter { public Observable<List<ImplementationReportViewModel>> getImplementationViewModelsForCurrentMalariaProgram(final Period period) { this.period = period; return Observable.create((Observable.OnSubscribe<List<ImplementationReportViewModel>>) subscriber -> { try { malariaProgram = patientDataService.findForPeriod(period.getBegin(), period.getEnd()); MalariaDataReportViewModel malariaDataReportViewModel = reportViewModelMapper.Map(malariaProgram); ImplementationReportViewModel usImplementationReportViewModel = malariaDataReportViewModel.getUsImplementationReportViewModel(); if (malariaProgram != null) { createdBy = malariaProgram.getCreatedBy(); status = malariaProgram.getStatus(); } else { createdBy = ""; status = ViaReportStatus.MISSING; List<Long> malariaProductsStockHand = patientDataService.getMalariaProductsStockHand(); usImplementationReportViewModel.setExistingStock(malariaProductsStockHand); } viewModels.add(usImplementationReportViewModel); viewModels.add(malariaDataReportViewModel.getApeImplementationReportViewModel()); viewModels.add(generateTotalViewModel(viewModels.get(0), viewModels.get(1))); subscriber.onNext(viewModels); subscriber.onCompleted(); } catch (Exception e) { new LMISException(e, "MalariaData:getImple").reportToFabric(); subscriber.onError(e); } }).observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.io()); } MalariaDataReportFormPresenter(); }
MalariaDataReportFormPresenter extends BaseReportPresenter { public Observable<List<ImplementationReportViewModel>> getImplementationViewModelsForCurrentMalariaProgram(final Period period) { this.period = period; return Observable.create((Observable.OnSubscribe<List<ImplementationReportViewModel>>) subscriber -> { try { malariaProgram = patientDataService.findForPeriod(period.getBegin(), period.getEnd()); MalariaDataReportViewModel malariaDataReportViewModel = reportViewModelMapper.Map(malariaProgram); ImplementationReportViewModel usImplementationReportViewModel = malariaDataReportViewModel.getUsImplementationReportViewModel(); if (malariaProgram != null) { createdBy = malariaProgram.getCreatedBy(); status = malariaProgram.getStatus(); } else { createdBy = ""; status = ViaReportStatus.MISSING; List<Long> malariaProductsStockHand = patientDataService.getMalariaProductsStockHand(); usImplementationReportViewModel.setExistingStock(malariaProductsStockHand); } viewModels.add(usImplementationReportViewModel); viewModels.add(malariaDataReportViewModel.getApeImplementationReportViewModel()); viewModels.add(generateTotalViewModel(viewModels.get(0), viewModels.get(1))); subscriber.onNext(viewModels); subscriber.onCompleted(); } catch (Exception e) { new LMISException(e, "MalariaData:getImple").reportToFabric(); subscriber.onError(e); } }).observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.io()); } MalariaDataReportFormPresenter(); @Override void attachView(BaseView v); Observable<List<ImplementationReportViewModel>> getImplementationViewModelsForCurrentMalariaProgram(final Period period); MalariaProgram getMalariaProgram(); List<ImplementationReportViewModel> regenerateImplementationModels(ImplementationReportViewModel updatedViewModel); Observable<MalariaProgram> onSaveForm(final ViaReportStatus status, final String sign); @Override void deleteDraft(); @Override boolean isDraft(); boolean isSubmittedForApproval(); }
MalariaDataReportFormPresenter extends BaseReportPresenter { public Observable<List<ImplementationReportViewModel>> getImplementationViewModelsForCurrentMalariaProgram(final Period period) { this.period = period; return Observable.create((Observable.OnSubscribe<List<ImplementationReportViewModel>>) subscriber -> { try { malariaProgram = patientDataService.findForPeriod(period.getBegin(), period.getEnd()); MalariaDataReportViewModel malariaDataReportViewModel = reportViewModelMapper.Map(malariaProgram); ImplementationReportViewModel usImplementationReportViewModel = malariaDataReportViewModel.getUsImplementationReportViewModel(); if (malariaProgram != null) { createdBy = malariaProgram.getCreatedBy(); status = malariaProgram.getStatus(); } else { createdBy = ""; status = ViaReportStatus.MISSING; List<Long> malariaProductsStockHand = patientDataService.getMalariaProductsStockHand(); usImplementationReportViewModel.setExistingStock(malariaProductsStockHand); } viewModels.add(usImplementationReportViewModel); viewModels.add(malariaDataReportViewModel.getApeImplementationReportViewModel()); viewModels.add(generateTotalViewModel(viewModels.get(0), viewModels.get(1))); subscriber.onNext(viewModels); subscriber.onCompleted(); } catch (Exception e) { new LMISException(e, "MalariaData:getImple").reportToFabric(); subscriber.onError(e); } }).observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.io()); } MalariaDataReportFormPresenter(); @Override void attachView(BaseView v); Observable<List<ImplementationReportViewModel>> getImplementationViewModelsForCurrentMalariaProgram(final Period period); MalariaProgram getMalariaProgram(); List<ImplementationReportViewModel> regenerateImplementationModels(ImplementationReportViewModel updatedViewModel); Observable<MalariaProgram> onSaveForm(final ViaReportStatus status, final String sign); @Override void deleteDraft(); @Override boolean isDraft(); boolean isSubmittedForApproval(); static final int INVALID_INDEX; }