### Question:
MeasurementUtils { public static double userTrueDistanceFromStep(Point usersRawLocation, LegStep step) { if (TextUtils.isEmpty(step.geometry())) { return 0; } LineString lineString = LineString.fromPolyline(step.geometry(), Constants.PRECISION_6); if (lineString.coordinates().isEmpty() || usersRawLocation.equals(lineString.coordinates().get(0))) { return 0; } if (lineString.coordinates().size() == 1) { return TurfMeasurement.distance(usersRawLocation, lineString.coordinates().get(0), UNIT_METERS); } Feature feature = TurfMisc.nearestPointOnLine(usersRawLocation, lineString.coordinates()); Point snappedPoint = (Point) feature.geometry(); if (snappedPoint == null) { return 0; } if (Double.isInfinite(snappedPoint.latitude()) || Double.isInfinite(snappedPoint.longitude())) { return TurfMeasurement.distance(usersRawLocation, lineString.coordinates().get(0), UNIT_METERS); } double distance = TurfMeasurement.distance(usersRawLocation, snappedPoint, UNIT_METERS); return Double.isNaN(distance) ? 0d : distance; } private  MeasurementUtils(); static double userTrueDistanceFromStep(Point usersRawLocation, LegStep step);  }### Answer:
@Test public void userTrueDistanceFromStep_returnsZeroWhenCurrentStepAndPointEqualSame() { Point futurePoint = Point.fromLngLat(-95.367697, 29.758938); List<Point> geometryPoints = new ArrayList<>(); geometryPoints.add(futurePoint); double[] rawLocation = {0, 0}; LegStep step = getLegStep(rawLocation, geometryPoints); double distance = MeasurementUtils.userTrueDistanceFromStep(futurePoint, step); assertEquals(0d, distance, DELTA); }
@Test public void userTrueDistanceFromStep_onlyOnePointInLineStringStillMeasuresDistanceCorrectly() { Point futurePoint = Point.fromLngLat(-95.3676974, 29.7589382); List<Point> geometryPoints = new ArrayList<>(); geometryPoints.add(Point.fromLngLat(-95.8427, 29.7757)); double[] rawLocation = {0, 0}; LegStep step = getLegStep(rawLocation, geometryPoints); double distance = MeasurementUtils.userTrueDistanceFromStep(futurePoint, step); assertEquals(45900.73617999494, distance, DELTA); }
@Test public void userTrueDistanceFromStep_onePointStepGeometryWithDifferentRawPoint() { Point futurePoint = Point.fromLngLat(-95.3676974, 29.7589382); List<Point> geometryPoints = new ArrayList<>(); geometryPoints.add(Point.fromLngLat(-95.8427, 29.7757)); geometryPoints.add(futurePoint); double[] rawLocation = {0, 0}; LegStep step = getLegStep(rawLocation, geometryPoints); double distance = MeasurementUtils.userTrueDistanceFromStep(futurePoint, step); assertEquals(0.04457271773629306d, distance, DELTA); }