AppRemotePresenter { public void loadIncidentForm(AppRemoteService.LoadCallback callback) { formRemoteService.getIncidentForm(PrimeroAppConfiguration.getCookie(), PrimeroAppConfiguration.getDefaultLanguage (), true, PrimeroAppConfiguration.PARENT_INCIDENT, MODULE_ID_GBV) .subscribe(incidentForm -> { saveIncidentForm(incidentForm); 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_incident_form_when_give_cookie_and_module_id() throws Exception { IncidentTemplateForm incidentTemplateForm = createIncidentTemplateForm(); Observable<IncidentTemplateForm> observable = Observable.just(incidentTemplateForm); when(formRemoteService.getIncidentForm("cookie", "en", true, "incident", "primeromodule-gbv")).thenReturn(observable); Mockito.when(PrimeroAppConfiguration.getCookie()).thenReturn("cookie"); Mockito.when(PrimeroAppConfiguration.getDefaultLanguage()).thenReturn("en"); AppRemoteService.LoadCallback callback = mock(AppRemoteService.LoadCallback.class); appRemotePresenter.loadIncidentForm(callback); verify(incidentFormService, times(1)).saveOrUpdate(any(IncidentForm.class)); verify(callback, times(1)).onSuccess(); verify(callback, never()).onFailure(); }
@Test public void should_show_error_when_sync_incident_form_fail() throws Exception { Observable observable = Observable.error(new Exception()); when(formRemoteService.getIncidentForm("cookie", "en", true, "incident", "primeromodule-gbv")) .thenReturn(observable); Mockito.when(PrimeroAppConfiguration.getCookie()).thenReturn("cookie"); Mockito.when(PrimeroAppConfiguration.getDefaultLanguage()).thenReturn("en"); AppRemoteService.LoadCallback callback = mock(AppRemoteService.LoadCallback.class); appRemotePresenter.loadIncidentForm(callback); verify(callback, times(1)).onFailure(); verify(callback, never()).onSuccess(); }