IncidentService extends RecordService { public Incident deleteByRecordId(long recordId) { Incident deleteIncident = incidentDao.getIncidentById(recordId); if (deleteIncident != null && !deleteIncident.isSynced()) { return null; } incidentDao.delete(deleteIncident); return deleteIncident; } IncidentService();  IncidentService(IncidentDao incidentDao); Incident getById(long incidentId); Incident getByUniqueId(String uniqueId); List<Incident> getAll(); List<Long> getAllOrderByDateASC(); List<Long> getAllOrderByDateDES(); List<Long> getAllOrderByAgeASC(); List<Long> getAllOrderByAgeDES(); List<Long> getSearchResult(String uniqueId, String survivorCode, int ageFrom, int ageTo, String
            typeOfViolence, String location); Incident saveOrUpdate(ItemValuesMap itemValues); Incident save(ItemValuesMap itemValues); Incident update(ItemValuesMap itemValues); Incident deleteByRecordId(long recordId); Incident getByInternalId(String id); boolean hasSameRev(String id, String rev); List<Long> getAllSyncedRecordsId(); static final String TAG; static final String INCIDENT_DISPLAY_ID; static final String INCIDENT_ID; static final String INCIDENT_PRIMARY_ID; static final String EMPTY_ID; }
@Test public void should_delete_when_incident_exists_and_synced_yet() throws Exception { long recordId = 123L; Incident deleteIncident = new Incident(recordId); deleteIncident.setSynced(true); when(incidentDao.getIncidentById(recordId)).thenReturn(deleteIncident); Incident actual = incidentService.deleteByRecordId(recordId); verify(incidentDao, times(1)).delete(deleteIncident); assertThat(actual, is(deleteIncident)); }
@Test public void should_not_delete_when_incident_exists_and_not_synced_yet() throws Exception { long recordId = 123L; Incident deleteIncident = new Incident(recordId); deleteIncident.setSynced(false); when(incidentDao.getIncidentById(recordId)).thenReturn(deleteIncident); Incident actual = incidentService.deleteByRecordId(recordId); verify(incidentDao, never()).delete(deleteIncident); assertNull(actual); }