CaseFormServiceImpl implements CaseFormService { public void saveOrUpdate(CaseForm caseForm) { CaseForm existingCaseForm = caseFormDao.getCaseForm(caseForm.getModuleId(), PrimeroAppConfiguration .getApiBaseUrl()); if (existingCaseForm == null) { caseForm.setServerUrl(PrimeroAppConfiguration.getApiBaseUrl()); caseForm.save(); } else { existingCaseForm.setForm(caseForm.getForm()); existingCaseForm.update(); } } CaseFormServiceImpl(CaseFormDao caseFormDao); boolean isReady(); CaseTemplateForm getCPTemplate(); @Override CaseTemplateForm getGBVTemplate(); void saveOrUpdate(CaseForm caseForm); static final String TAG; }
@Test public void should_save_case_form_if_not_exist() throws Exception { CaseForm caseForm = mock(CaseForm.class); when(caseFormDao.getCaseForm("primeromodule-cp", PrimeroAppConfiguration.getApiBaseUrl())).thenReturn(null); caseFormService.saveOrUpdate(caseForm); verify(caseForm, times(1)).save(); }
@Test public void should_update_case_form_if_exist() throws Exception { CaseForm caseForm = mock(CaseForm.class); when(caseForm.getModuleId()).thenReturn("primeromodule-cp"); Blob formBlob = mock(Blob.class); when(caseForm.getForm()).thenReturn(formBlob); when(caseFormDao.getCaseForm("primeromodule-cp", PrimeroAppConfiguration.getApiBaseUrl())).thenReturn(caseForm); caseFormService.saveOrUpdate(caseForm); verify(caseForm, times(1)).setForm(formBlob); verify(caseForm, times(1)).update(); }