FormInstanceMapper { @NonNull public List<Long> getInstanceIds(Cursor cursor) { int count = cursor == null? 0: cursor.getCount(); List<Long> surveyInstanceIds = new ArrayList<>(count); if (cursor != null) { if (cursor.moveToFirst()) { do { surveyInstanceIds.add(getInstanceId(cursor)); } while (cursor.moveToNext()); } cursor.close(); } return surveyInstanceIds; } @Inject  FormInstanceMapper(TextValueCleaner textValueCleaner,
            ResponseMapper responseMapper, FileHelper fileHelper); @NonNull List<InstanceIdUuid> getInstanceIdUuids(Cursor cursor); @NonNull List<Long> getInstanceIds(Cursor cursor); @NonNull Pair<FormInstance, Set<String>> getFormInstanceWithMedia(@NonNull String deviceId,
            Cursor data); @NonNull FormInstance getFormInstance(@NonNull String deviceId, Cursor data); Long getFormInstanceId(Cursor cursor);  }
@Test public void getInstanceIdsShouldReturnEmptyIfNullCursor() { List<Long> results = mapper.getInstanceIds(null); assertTrue(results.isEmpty()); }
@Test public void getInstanceIdsShouldReturnEmptyIfEmptyCursor() { when(mockCursor.moveToFirst()).thenReturn(false); List<Long> results = mapper.getInstanceIds(mockCursor); assertTrue(results.isEmpty()); }
@Test public void getInstanceIdsShouldReturnCorrectDataIfNonEmptyCursor() { when(mockCursor.moveToFirst()).thenReturn(true); when(mockCursor.getCount()).thenReturn(1); when(mockCursor.moveToNext()).thenReturn(false); List<Long> results = mapper.getInstanceIds(mockCursor); assertFalse(results.isEmpty()); assertEquals(1L, results.get(0).longValue()); }