### Question:
ExerciseViewModel { public void setAvgSpeedFloatValue(float fAvgSpeedMetric) { float fAvgSpeedCurrentUnit = fAvgSpeedMetric; if (this.formatUtils.getUnitSystem() == UnitSystem.ENGLISH) { fAvgSpeedCurrentUnit = (float) ConvertUtils.convertKilometer2Miles(fAvgSpeedMetric, false); } this.avgSpeed.set(speedConverter.floatSpeedtoString(fAvgSpeedCurrentUnit)); } ExerciseViewModel(final Exercise exercise, final FormatUtils formatUtils, final SpeedMode preferredSpeedMode); Exercise getExercise(); SpeedToStringConverter getSpeedConverter(); void setAutoCalcFields(final float newDistance, final float newAvgSpeed, final int newDuration); void setAvgSpeedFloatValue(float fAvgSpeedMetric); final ObjectProperty<LocalDate> date; final ObjectProperty<LocalTime> time; final ObjectProperty<SportType> sportType; final ObjectProperty<SportSubType> sportSubType; final ObjectProperty<Exercise.IntensityType> intensity; final FloatProperty distance; final IntegerProperty duration; final IntegerProperty avgHeartRate; final IntegerProperty ascent; final IntegerProperty descent; final IntegerProperty calories; final ObjectProperty<Equipment> equipment; final StringProperty hrmFile; final StringProperty comment; final StringProperty avgSpeed; final BooleanProperty sportTypeRecordDistance; final BooleanProperty autoCalcDistance; final BooleanProperty autoCalcAvgSpeed; final BooleanProperty autoCalcDuration; }### Answer:
@Test public void testSetAvgSpeedFloatValueMetricSpeed() { ExerciseViewModel viewModel = new ExerciseViewModel(exercise, new FormatUtils(UnitSystem.METRIC), SpeedMode.SPEED); viewModel.setAvgSpeedFloatValue(21.3f); assertEquals("21.3", viewModel.avgSpeed.get()); }
@Test public void testSetAvgSpeedFloatValueEnglishPace() { exercise.getSportType().setSpeedMode(SpeedMode.PACE); ExerciseViewModel viewModel = new ExerciseViewModel(exercise, new FormatUtils(UnitSystem.ENGLISH), SpeedMode.SPEED); viewModel.setAvgSpeedFloatValue(21.3f); assertEquals("04:32", viewModel.avgSpeed.get()); }
@Test public void testSetAvgSpeedFloatValueEnglishPaceZero() { exercise.getSportType().setSpeedMode(SpeedMode.PACE); ExerciseViewModel viewModel = new ExerciseViewModel(exercise, new FormatUtils(UnitSystem.ENGLISH), SpeedMode.SPEED); viewModel.setAvgSpeedFloatValue(0f); assertEquals("00:00", viewModel.avgSpeed.get()); }