CaseService extends RecordService { public List<String> getIncidentsByCaseId(String caseUniqueId) { List<Incident> incidents = incidentDao.getAllIncidentsByCaseUniqueId(caseUniqueId); if (incidents == null || incidents.isEmpty()) { return null; } return extractUniqueIds(incidents); } CaseService(CaseDao caseDao, CasePhotoDao casePhotoDao, IncidentDao incidentDao); List<Case> getAll(); Case getById(long caseId); Case getByUniqueId(String uniqueId); List<String> getIncidentsByCaseId(String caseUniqueId); List<Long> getAllOrderByDateASC(); List<Long> getAllOrderByDateDES(); List<Long> getAllOrderByAgeASC(); List<Long> getAllOrderByAgeDES(); List<Long> getCPSearchResult(String shortId, String name, int ageFrom, int ageTo,
                                        String caregiver, Date date); List<Long> getAllSyncedRecordsId(); List<Long> getGBVSearchResult(String shortId, String name, String location, Date registrationDate); Case saveOrUpdate(ItemValuesMap itemValues, List<String> photoPaths); Case save(ItemValuesMap itemValues, List<String> photoPaths); void savePhoto(Case child, List<String> photoPaths); Case update(ItemValuesMap itemValues, List<String> photoBitPaths); void updatePhoto(Case child, List<String> photoPaths); Case deleteByRecordId(long recordId); Case getByInternalId(String id); boolean hasSameRev(String id, String rev); static final String TAG; static final String CASE_DISPLAY_ID; static final String CASE_ID; static final String CASE_PRIMARY_ID; }
@Test public void should_get_null_incidents_ids_when_incidents_is_null() throws Exception { when(incidentDao.getAllIncidentsByCaseUniqueId(anyString())).thenReturn(null); List<String> incidents = caseService.getIncidentsByCaseId(""); assertThat("Incidents should be null", incidents, is(nullValue())); }
@Test public void should_get_incidents_ids_when_incidents_exits() throws Exception { List<Incident> incidents = new ArrayList<>(); Incident incident = new Incident(10086L); incidents.add(incident); List<String> listStr = new ArrayList<>(); CaseService caseServiceSpy = spy(caseService); when(incidentDao.getAllIncidentsByCaseUniqueId(anyString())).thenReturn(incidents); when(caseServiceSpy.extractUniqueIds(incidents)).thenReturn(listStr); assertThat("Should return same incident string list", caseServiceSpy.getIncidentsByCaseId(""), is(listStr)); }