FormInstanceMapper { @NonNull public List<InstanceIdUuid> getInstanceIdUuids(Cursor cursor) { int size = cursor == null ? 0 : cursor.getCount(); List<InstanceIdUuid> instanceIdUuids = new ArrayList<>(size); if (cursor != null && cursor.moveToFirst()) { do { instanceIdUuids.add(getInstanceIdUuid(cursor)); } while (cursor.moveToNext()); } if (cursor != null) { cursor.close(); } return instanceIdUuids; } @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 getInstanceIdUuidsShouldReturnEmptyIfNullCursor() { List<InstanceIdUuid> results = mapper.getInstanceIdUuids(null); assertTrue(results.isEmpty()); }
@Test public void getInstanceIdUuidsShouldReturnEmptyIfEmptyCursor() { mapper = new FormInstanceMapper(mockTextValueCleaner, mockResponseMapper, mockFileHelper); when(mockCursor.moveToFirst()).thenReturn(false); List<InstanceIdUuid> results = mapper.getInstanceIdUuids(mockCursor); assertTrue(results.isEmpty()); }
@Test public void getInstanceIdUuidsShouldReturnCorrectDataFromCursor() { mapper = new FormInstanceMapper(mockTextValueCleaner, mockResponseMapper, mockFileHelper); when(mockCursor.moveToFirst()).thenReturn(true); when(mockCursor.getCount()).thenReturn(1); when(mockCursor.moveToNext()).thenReturn(false); List<InstanceIdUuid> results = mapper.getInstanceIdUuids(mockCursor); assertFalse(results.isEmpty()); InstanceIdUuid instanceIdUuid = results.get(0); assertEquals(1L, instanceIdUuid.getId()); assertEquals("uuid", instanceIdUuid.getUuid()); }