TracingService extends RecordService { public Tracing deleteByRecordId(long recordId) { Tracing deleteTracing = tracingDao.getTracingById(recordId); if (deleteTracing != null && !deleteTracing.isSynced()) { return null; } tracingDao.delete(deleteTracing); tracingPhotoDao.deleteByTracingId(recordId); return deleteTracing; } TracingService(TracingDao tracingDao, TracingPhotoDao tracingPhotoDao); Tracing getById(long tracingId); Tracing getByUniqueId(String uniqueId); List<Tracing> getAll(); List<Long> getAllOrderByDateASC(); List<Long> getAllOrderByDateDES(); List<Long> getSearchResult(String uniqueId, String name, int ageFrom, int ageTo, Date
            date); Tracing saveOrUpdate(ItemValuesMap itemValues, List<String> photoPaths); Tracing save(ItemValuesMap itemValues, List<String> photoPaths); Tracing update(ItemValuesMap itemValues,
                          List<String> photoBitPaths); Tracing deleteByRecordId(long recordId); Tracing getByInternalId(String id); boolean hasSameRev(String id, String rev); List<Long> getAllSyncedRecordsId(); static final String TAG; static final String TRACING_DISPLAY_ID; static final String TRACING_ID; static final String TRACING_PRIMARY_ID; }
@Test public void should_delete_when_tracing_exists_and_synced_yet() throws Exception { long recordId = 123L; Tracing deleteTracing = new Tracing(recordId); deleteTracing.setSynced(true); when(tracingDao.getTracingById(recordId)).thenReturn(deleteTracing); Tracing actual = tracingService.deleteByRecordId(recordId); verify(tracingDao, times(1)).delete(deleteTracing); assertThat(actual, is(deleteTracing)); }
@Test public void should_not_delete_when_tracing_exists_and_not_synced_yet() throws Exception { long recordId = 123L; Tracing deleteTracing = new Tracing(recordId); deleteTracing.setSynced(false); when(tracingDao.getTracingById(recordId)).thenReturn(deleteTracing); Tracing actual = tracingService.deleteByRecordId(recordId); verify(tracingDao, never()).delete(deleteTracing); assertNull(actual); }