AppRemotePresenter { public void loadCaseForm(String moduleId, AppRemoteService.LoadCallback callback) { formRemoteService.getCaseForm(PrimeroAppConfiguration.getCookie(), PrimeroAppConfiguration.getDefaultLanguage (), true, PrimeroAppConfiguration.PARENT_CASE, moduleId) .subscribe(caseForm -> { saveCaseForm(caseForm, moduleId); callback.onSuccess(); }, throwable -> callback.onFailure()); } @Inject  AppRemotePresenter(Lazy<FormRemoteService> formRemoteService,
                              CaseFormService caseFormService,
                              TracingFormService tracingFormService,
                              IncidentFormService incidentFormService,
                              Lazy<SystemSettingsService> systemSettingsService);  AppRemotePresenter(FormRemoteService formRemoteService,
                              CaseFormService caseFormService,
                              TracingFormService tracingFormService,
                              IncidentFormService incidentFormService,
                              SystemSettingsService systemSettingsService); void loadCaseForm(String moduleId, AppRemoteService.LoadCallback callback); void saveCaseForm(RecordForm recordForm, String moduleId); void loadTracingForm(AppRemoteService.LoadCallback callback); void saveTracingForm(RecordForm recordForm); void loadIncidentForm(AppRemoteService.LoadCallback callback); void saveIncidentForm(RecordForm recordForm); void loadSystemSettings();  }
@Test public void should_load_case_form_when_give_cookie_and_module_id() throws Exception { CaseTemplateForm caseTemplateForm = createCaseTemplateForm(); Observable<CaseTemplateForm> observable = Observable.just(caseTemplateForm); when(formRemoteService.getCaseForm("cookie", "en", true, "case", PrimeroAppConfiguration.MODULE_ID_CP)) .thenReturn(observable); when(PrimeroAppConfiguration.getCookie()).thenReturn("cookie"); when(PrimeroAppConfiguration.getDefaultLanguage()).thenReturn("en"); AppRemoteService.LoadCallback callback = mock(AppRemoteService.LoadCallback.class); appRemotePresenter.loadCaseForm(PrimeroAppConfiguration.MODULE_ID_CP, callback); verify(caseFormService, times(1)).saveOrUpdate(any(CaseForm.class)); verify(callback, times(1)).onSuccess(); verify(callback, never()).onFailure(); }
@Test public void should_show_error_when_sync_case_form_fail() throws Exception { Observable observable = Observable.error(new Exception()); when(formRemoteService.getCaseForm("cookie", "en", true, "case", "primeromodule-cp")) .thenReturn(observable); when(PrimeroAppConfiguration.getCookie()).thenReturn("cookie"); when(PrimeroAppConfiguration.getDefaultLanguage()).thenReturn("en"); AppRemoteService.LoadCallback callback = mock(AppRemoteService.LoadCallback.class); appRemotePresenter.loadCaseForm("primeromodule-cp", callback); verify(callback, times(1)).onFailure(); verify(callback, never()).onSuccess(); }