IncidentFormServiceImpl implements IncidentFormService { public void saveOrUpdate(IncidentForm incidentForm) { IncidentForm existingIncidentForm = incidentFormDao.getIncidentForm(incidentForm. getModuleId(),PrimeroAppConfiguration.getApiBaseUrl()); if (existingIncidentForm == null) { incidentForm.setServerUrl(PrimeroAppConfiguration.getApiBaseUrl()); incidentForm.save(); } else { existingIncidentForm.setForm(incidentForm.getForm()); existingIncidentForm.update(); } } IncidentFormServiceImpl(IncidentFormDao incidentFormDao); boolean isReady(); @Override IncidentTemplateForm getGBVTemplate(); void saveOrUpdate(IncidentForm incidentForm); @Override List<String> getViolenceTypeList(); @Override List<String> getLocationList(); static final String TAG; static final String SECTION_TYPE_OF_VIOLENCE; static final String SECTION_GBV_INCIDENT; }
@Test public void should_save_when_existing_incident_form_is_null() { when(incidentFormDao.getIncidentForm(anyString(), anyString())).thenReturn(null); IncidentForm incidentForm = mock(IncidentForm.class); incidentFormService.saveOrUpdate(incidentForm); verify(incidentForm, times(1)).save(); }
@Test public void should_update_when_existing_incident_form_is_not_null() { IncidentForm existingIncidentForm = mock(IncidentForm.class); when(incidentFormDao.getIncidentForm(anyString(), anyString())).thenReturn(existingIncidentForm); IncidentForm incidentForm = mock(IncidentForm.class); incidentFormService.saveOrUpdate(incidentForm); verify(existingIncidentForm,times(1)).setForm(incidentForm.getForm()); verify(existingIncidentForm,times(1)).update(); }