@Test public void shouldBuildFormListViewModels() throws LMISException { presenter.setProgramCode("MMIA"); presenter.setViewProgram(Constants.Program.MMIA_PROGRAM); Collections.reverse(rnRForms); when(rnrFormRepository.listInclude(any(RnRForm.Emergency.class), anyString(), anyObject())).thenReturn(rnRForms); when(syncErrorsRepository.getBySyncTypeAndObjectId(any(SyncType.class), anyLong())) .thenReturn(Arrays.asList(new SyncError("Error1", SyncType.RnRForm, 1), new SyncError("Error2", SyncType.RnRForm, 1))); ReportTypeForm reportTypeForm = new ReportTypeFormBuilder(). setActive(true). setCode(Constants.MMIA_REPORT). setName(Constants.MMIA_PROGRAM_CODE). setStartTime(new DateTime(DateUtil.parseString("2016-02-5", DateUtil.DB_DATE_FORMAT)).toDate()) .build(); when(reportTypeFormRepository.queryByCode(Constants.MMIA_REPORT)).thenReturn(reportTypeForm); List<RnRFormViewModel> resultViewModels = presenter.buildFormListViewModels(); assertThat(resultViewModels.size()).isEqualTo(3); assertThat(resultViewModels.get(0).getSyncServerErrorMessage()).isEqualTo("Error2"); }
@NonNull protected List<RnRFormViewModel> buildFormListViewModels() throws LMISException { List<RnRFormViewModel> rnRFormViewModels = new ArrayList<>(); ReportTypeForm typeForm = reportTypeFormRepository.queryByCode(viewProgram.getReportType()); List<RnRForm> rnRForms = repository.listInclude(RnRForm.Emergency.Yes, programCode, typeForm); generateRnrViewModelByRnrFormsInDB(rnRFormViewModels, rnRForms); if (typeForm.active) { generateViewModelsByCurrentDate(rnRFormViewModels, typeForm); } populateSyncErrorsOnViewModels(rnRFormViewModels); Collections.sort(rnRFormViewModels, (lhs, rhs) -> rhs.getPeriodEndMonth().compareTo(lhs.getPeriodEndMonth())); generateInactiveFormListViewModels(rnRFormViewModels, typeForm); return rnRFormViewModels; }
RnRFormListPresenter extends Presenter { @NonNull protected List<RnRFormViewModel> buildFormListViewModels() throws LMISException { List<RnRFormViewModel> rnRFormViewModels = new ArrayList<>(); ReportTypeForm typeForm = reportTypeFormRepository.queryByCode(viewProgram.getReportType()); List<RnRForm> rnRForms = repository.listInclude(RnRForm.Emergency.Yes, programCode, typeForm); generateRnrViewModelByRnrFormsInDB(rnRFormViewModels, rnRForms); if (typeForm.active) { generateViewModelsByCurrentDate(rnRFormViewModels, typeForm); } populateSyncErrorsOnViewModels(rnRFormViewModels); Collections.sort(rnRFormViewModels, (lhs, rhs) -> rhs.getPeriodEndMonth().compareTo(lhs.getPeriodEndMonth())); generateInactiveFormListViewModels(rnRFormViewModels, typeForm); return rnRFormViewModels; } }
RnRFormListPresenter extends Presenter { @NonNull protected List<RnRFormViewModel> buildFormListViewModels() throws LMISException { List<RnRFormViewModel> rnRFormViewModels = new ArrayList<>(); ReportTypeForm typeForm = reportTypeFormRepository.queryByCode(viewProgram.getReportType()); List<RnRForm> rnRForms = repository.listInclude(RnRForm.Emergency.Yes, programCode, typeForm); generateRnrViewModelByRnrFormsInDB(rnRFormViewModels, rnRForms); if (typeForm.active) { generateViewModelsByCurrentDate(rnRFormViewModels, typeForm); } populateSyncErrorsOnViewModels(rnRFormViewModels); Collections.sort(rnRFormViewModels, (lhs, rhs) -> rhs.getPeriodEndMonth().compareTo(lhs.getPeriodEndMonth())); generateInactiveFormListViewModels(rnRFormViewModels, typeForm); return rnRFormViewModels; }  }
RnRFormListPresenter extends Presenter { @NonNull protected List<RnRFormViewModel> buildFormListViewModels() throws LMISException { List<RnRFormViewModel> rnRFormViewModels = new ArrayList<>(); ReportTypeForm typeForm = reportTypeFormRepository.queryByCode(viewProgram.getReportType()); List<RnRForm> rnRForms = repository.listInclude(RnRForm.Emergency.Yes, programCode, typeForm); generateRnrViewModelByRnrFormsInDB(rnRFormViewModels, rnRForms); if (typeForm.active) { generateViewModelsByCurrentDate(rnRFormViewModels, typeForm); } populateSyncErrorsOnViewModels(rnRFormViewModels); Collections.sort(rnRFormViewModels, (lhs, rhs) -> rhs.getPeriodEndMonth().compareTo(lhs.getPeriodEndMonth())); generateInactiveFormListViewModels(rnRFormViewModels, typeForm); return rnRFormViewModels; }  @Override void attachView(BaseView v); Observable<List<RnRFormViewModel>> loadRnRFormList(); void deleteRnRForm(RnRForm form); Observable<Boolean> hasMissedPeriod(); }
RnRFormListPresenter extends Presenter { @NonNull protected List<RnRFormViewModel> buildFormListViewModels() throws LMISException { List<RnRFormViewModel> rnRFormViewModels = new ArrayList<>(); ReportTypeForm typeForm = reportTypeFormRepository.queryByCode(viewProgram.getReportType()); List<RnRForm> rnRForms = repository.listInclude(RnRForm.Emergency.Yes, programCode, typeForm); generateRnrViewModelByRnrFormsInDB(rnRFormViewModels, rnRForms); if (typeForm.active) { generateViewModelsByCurrentDate(rnRFormViewModels, typeForm); } populateSyncErrorsOnViewModels(rnRFormViewModels); Collections.sort(rnRFormViewModels, (lhs, rhs) -> rhs.getPeriodEndMonth().compareTo(lhs.getPeriodEndMonth())); generateInactiveFormListViewModels(rnRFormViewModels, typeForm); return rnRFormViewModels; }  @Override void attachView(BaseView v); Observable<List<RnRFormViewModel>> loadRnRFormList(); void deleteRnRForm(RnRForm form); Observable<Boolean> hasMissedPeriod();  }