DexcomAdapterService implements AdapterService<DexcomSyncData> { @Override public SyncData convertData(DexcomSyncData source) { List<GlucoseRead> glucoseReads = newArrayList(Collections2.filter(Collections2.transform(source.getGlucoseReads(), DEXCOM_GLUCOSE_RECORD_TO_GLUCOSE_READ), VALID_READS_FILTER)); DeviceInfo deviceInfo = DEXCOM_MANUFACTURING_PARAMS_TO_DEVICE_INFO.apply(source.getManufacturingParameters()); Collection<UserEventRecord> insulinEvents = Collections2.filter(source.getUserEvents(), INSULIN_EVENT_FILTER); Collection<UserEventRecord> exerciseEvents = Collections2.filter(source.getUserEvents(), EXERCISE_EVENT_FILTER); Collection<UserEventRecord> carbEvents = Collections2.filter(source.getUserEvents(), CARB_EVENT_FILTER); List<InsulinInjection> injections = newArrayList(Collections2.transform(insulinEvents, USER_EVENT_RECORD_TO_INSULIN_INJECTION)); List<ExerciseSession> exerciseSessions = newArrayList(Collections2.transform(exerciseEvents, USER_EVENT_RECORD_TO_EXERCISE_SESSION)); List<FoodEvent> foodEvents = newArrayList(Collections2.transform(carbEvents, USER_EVENT_RECORD_TO_FOOD_EVENT)); return new SyncData(glucoseReads, injections, foodEvents, exerciseSessions, deviceInfo, source.getUpdateTime()); }  @Override SyncData convertData(DexcomSyncData source); static final Predicate<GlucoseRead> VALID_READS_FILTER; }
@Test public void noReadsShouldConvertSuccessfully() throws Exception { DexcomAdapterService dexcomAdapterService = new DexcomAdapterService(); SyncData syncData = dexcomAdapterService.convertData( new DexcomSyncData(EMPTY_GLUCOSE_READ_RECORDS, EMPTY_USER_EVENT_RECORDS, new ManufacturingParameters(SERIAL_NUMBER, "partNumber", HARDWARE_REVISION, "2013-10-18 10:10", HARDWARE_ID), TEST_TIME)); SyncData expectedSyncData = new SyncData(EMPTY_GLUCOSE_READS, EMPTY_INSULIN_INJECTIONS, EMPTY_FOOD_EVENTS, EMPTY_EXERCISE_SESSIONS, new DeviceInfo(SERIAL_NUMBER, HARDWARE_ID, HARDWARE_REVISION), TEST_TIME); assertThat(syncData, is(equalTo(expectedSyncData))); }
@Test public void singleReadShouldConvertSuccessfully() throws Exception { DexcomAdapterService dexcomAdapterService = new DexcomAdapterService(); List<GlucoseReadRecord> glucoseRecords = Arrays.asList(new GlucoseReadRecord(1000, 1000, NORMAL_READ_TEST_VALUE, (byte) 0, 1L, 1L)); SyncData syncData = dexcomAdapterService.convertData(new DexcomSyncData(glucoseRecords, EMPTY_USER_EVENT_RECORDS, new ManufacturingParameters(SERIAL_NUMBER, "partNumber", HARDWARE_REVISION, "2013-10-18 10:10", HARDWARE_ID), TEST_TIME)); GlucoseRead expectedRead = new GlucoseRead( internalTimeFromSeconds(1000L), localDateTimeFromSeconds(1000L), NORMAL_READ_TEST_VALUE.floatValue(), GlucoseRead.Unit.MG_PER_DL); SyncData expectedSyncData = new SyncData(Arrays.asList(expectedRead), EMPTY_INSULIN_INJECTIONS, EMPTY_FOOD_EVENTS, EMPTY_EXERCISE_SESSIONS, new DeviceInfo(SERIAL_NUMBER, HARDWARE_ID, HARDWARE_REVISION), TEST_TIME); assertThat(syncData, is(equalTo(expectedSyncData))); }
@Test public void multipleReadsShouldAllBeConverted() throws Exception { DexcomAdapterService dexcomAdapterService = new DexcomAdapterService(); List<GlucoseReadRecord> glucoseRecords = Arrays.asList(new GlucoseReadRecord(1000, 1000, NORMAL_READ_TEST_VALUE, (byte) 0, 1L, 1L), new GlucoseReadRecord(2000, 2000, NORMAL_READ_TEST_VALUE, (byte) 0, 1L, 1L)); SyncData syncData = dexcomAdapterService.convertData(new DexcomSyncData(glucoseRecords, EMPTY_USER_EVENT_RECORDS, new ManufacturingParameters(SERIAL_NUMBER, "partNumber", HARDWARE_REVISION, "2013-10-18 10:10", HARDWARE_ID), TEST_TIME)); GlucoseRead expectedRead1 = new GlucoseRead( internalTimeFromSeconds(1000L), localDateTimeFromSeconds(1000L), NORMAL_READ_TEST_VALUE.floatValue(), GlucoseRead.Unit.MG_PER_DL); GlucoseRead expectedRead2 = new GlucoseRead( internalTimeFromSeconds(2000L), localDateTimeFromSeconds(2000L), NORMAL_READ_TEST_VALUE.floatValue(), GlucoseRead.Unit.MG_PER_DL); SyncData expectedSyncData = new SyncData(Arrays.asList(expectedRead1, expectedRead2), EMPTY_INSULIN_INJECTIONS, EMPTY_FOOD_EVENTS, EMPTY_EXERCISE_SESSIONS, new DeviceInfo(SERIAL_NUMBER, HARDWARE_ID, HARDWARE_REVISION), TEST_TIME); assertThat(syncData, is(equalTo(expectedSyncData))); }
@Test public void displayOnlyReadShouldNotBeIncluded() throws Exception { DexcomAdapterService dexcomAdapterService = new DexcomAdapterService(); List<GlucoseReadRecord> glucoseRecords = Arrays.asList(new GlucoseReadRecord(1000, 1000, 32781, (byte) 0, 1L, 1L)); SyncData syncData = dexcomAdapterService.convertData(new DexcomSyncData(glucoseRecords, EMPTY_USER_EVENT_RECORDS, new ManufacturingParameters(SERIAL_NUMBER, "partNumber", HARDWARE_REVISION, "2013-10-18 10:10", HARDWARE_ID), TEST_TIME)); SyncData expectedSyncData = new SyncData(EMPTY_GLUCOSE_READS, EMPTY_INSULIN_INJECTIONS, EMPTY_FOOD_EVENTS, EMPTY_EXERCISE_SESSIONS, new DeviceInfo(SERIAL_NUMBER, HARDWARE_ID, HARDWARE_REVISION), TEST_TIME); assertThat(syncData, is(equalTo(expectedSyncData))); }
@Test public void specialValuesShouldNotBeIncluded() throws Exception { DexcomAdapterService dexcomAdapterService = new DexcomAdapterService(); for (int specialGlucoseValue : SPECIAL_GLUCOSE_VALUES) { List<GlucoseReadRecord> glucoseRecords = Arrays.asList(new GlucoseReadRecord(1000, 1000, specialGlucoseValue, (byte) 0, 1L, 1L)); SyncData syncData = dexcomAdapterService.convertData(new DexcomSyncData(glucoseRecords, EMPTY_USER_EVENT_RECORDS, new ManufacturingParameters(SERIAL_NUMBER, "partNumber", HARDWARE_REVISION, "2013-10-18 10:10", HARDWARE_ID), TEST_TIME)); SyncData expectedSyncData = new SyncData(EMPTY_GLUCOSE_READS, EMPTY_INSULIN_INJECTIONS, EMPTY_FOOD_EVENTS, EMPTY_EXERCISE_SESSIONS, new DeviceInfo(SERIAL_NUMBER, HARDWARE_ID, HARDWARE_REVISION), TEST_TIME); assertThat(format("Glucose value [%d] should not be included in the conversion result", specialGlucoseValue), syncData, is(equalTo(expectedSyncData))); } }
@Test public void insulinUserRecordShouldBeConverted() throws Exception { DexcomAdapterService dexcomAdapterService = new DexcomAdapterService(); SyncData syncData = dexcomAdapterService.convertData( new DexcomSyncData(EMPTY_GLUCOSE_READ_RECORDS, Arrays.asList(new UserEventRecord(1000L, 2000L, 1500L, UserEventRecord.UserEventType.INSULIN, (byte) 0, 350)), new ManufacturingParameters(SERIAL_NUMBER, "partNumber", HARDWARE_REVISION, "2013-10-18 10:10", HARDWARE_ID), TEST_TIME)); InsulinInjection expectedInsulinInjection = new InsulinInjection(internalTimeFromSeconds(1000L), localDateTimeFromSeconds(2000L), localDateTimeFromSeconds(1500L), 3.5f, UNKNOWN, UNAVAILABLE_INSULIN_NAME); SyncData expectedSyncData = new SyncData(EMPTY_GLUCOSE_READS, Arrays.asList(expectedInsulinInjection), EMPTY_FOOD_EVENTS, EMPTY_EXERCISE_SESSIONS, new DeviceInfo(SERIAL_NUMBER, HARDWARE_ID, HARDWARE_REVISION), TEST_TIME); assertThat(syncData, is(equalTo(expectedSyncData))); }
@Test public void exerciseUserRecordShouldBeConverted() throws Exception { DexcomAdapterService dexcomAdapterService = new DexcomAdapterService(); SyncData syncData = dexcomAdapterService.convertData( new DexcomSyncData(EMPTY_GLUCOSE_READ_RECORDS, Arrays.asList(new UserEventRecord(1000L, 2000L, 1500L, UserEventRecord.UserEventType.EXERCISE, UserEventRecord.ExerciseIntensity.LIGHT.getId(), 10)), new ManufacturingParameters(SERIAL_NUMBER, "partNumber", HARDWARE_REVISION, "2013-10-18 10:10", HARDWARE_ID), TEST_TIME)); ExerciseSession expectedExerciseSession = new ExerciseSession(internalTimeFromSeconds(1000L), localDateTimeFromSeconds(2000L), localDateTimeFromSeconds(1500L), ExerciseSession.Intensity.LIGHT, Duration.ofMinutes(10), ExerciseSession.EMPTY_DESCRIPTION); SyncData expectedSyncData = new SyncData(EMPTY_GLUCOSE_READS, EMPTY_INSULIN_INJECTIONS, EMPTY_FOOD_EVENTS, Arrays.asList(expectedExerciseSession), new DeviceInfo(SERIAL_NUMBER, HARDWARE_ID, HARDWARE_REVISION), TEST_TIME); assertThat(syncData, is(equalTo(expectedSyncData))); }
@Test public void carbUserRecordShouldBeConverted() throws Exception { DexcomAdapterService dexcomAdapterService = new DexcomAdapterService(); SyncData syncData = dexcomAdapterService.convertData( new DexcomSyncData(EMPTY_GLUCOSE_READ_RECORDS, Arrays.asList(new UserEventRecord(1000L, 2000L, 1500L, UserEventRecord.UserEventType.CARBS, (byte) 0, 12)), new ManufacturingParameters(SERIAL_NUMBER, "partNumber", HARDWARE_REVISION, "2013-10-18 10:10", HARDWARE_ID), TEST_TIME)); FoodEvent foodEvent = new FoodEvent(internalTimeFromSeconds(1000L), localDateTimeFromSeconds(2000L), localDateTimeFromSeconds(1500L), 12f, 0f); SyncData expectedSyncData = new SyncData(EMPTY_GLUCOSE_READS, EMPTY_INSULIN_INJECTIONS, Arrays.asList(foodEvent), EMPTY_EXERCISE_SESSIONS, new DeviceInfo(SERIAL_NUMBER, HARDWARE_ID, HARDWARE_REVISION), TEST_TIME); assertThat(syncData, is(equalTo(expectedSyncData))); }