Skip to content

Commit

Permalink
Cleanup: SensorDataCyclingDistanceSpeed.Data is a record.
Browse files Browse the repository at this point in the history
  • Loading branch information
dennisguse committed Nov 15, 2023
1 parent 58d7938 commit d47fa27
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -562,13 +562,9 @@ private void mockBLESensorData(TrackPointCreator trackPointCreator, Float speed,
sensorDataSet.cyclingCadence = cyclingCadence;

if (distance != null && speed != null) {
SensorDataCyclingDistanceSpeed.Data distanceSpeedData = Mockito.mock(SensorDataCyclingDistanceSpeed.Data.class);
Mockito.when(distanceSpeedData.getDistanceOverall()).thenReturn(distance);
Mockito.when(distanceSpeedData.getSpeed()).thenReturn(Speed.of(speed));

SensorDataCyclingDistanceSpeed distanceSpeed = Mockito.mock(SensorDataCyclingDistanceSpeed.class);
Mockito.when(distanceSpeed.hasValue()).thenReturn(true);
Mockito.when(distanceSpeed.getValue()).thenReturn(distanceSpeedData);
Mockito.when(distanceSpeed.getValue()).thenReturn(new SensorDataCyclingDistanceSpeed.Data(null, distance, Speed.of(speed)));
sensorDataSet.cyclingDistanceSpeed = distanceSpeed;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ public void compute_speed() {
current.add(new Raw<>(new BluetoothHandlerCyclingDistanceSpeed.WheelData(2, 8016)));

// then
assertEquals(2.15, current.getValue().getDistance().toM(), 0.01);
assertEquals(1.20, current.getValue().getSpeed().toMPS(), 0.01);
assertEquals(2.15, current.getValue().distance().toM(), 0.01);
assertEquals(1.20, current.getValue().speed().toMPS(), 0.01);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,38 +73,5 @@ public void setWheelCircumference(Distance wheelCircumference) {
this.wheelCircumference = wheelCircumference;
}

// TODO Make record
public static class Data {
private final Distance distance;
private final Distance distanceOverall;
private final Speed speed;

private Data(Distance distance, Distance distanceOverall, Speed speed) {
this.distance = distance;
this.distanceOverall = distanceOverall;
this.speed = speed;
}

public Distance getDistance() {
return distance;
}

public Distance getDistanceOverall() {
return distanceOverall;
}

public Speed getSpeed() {
return speed;
}

@NonNull
@Override
public String toString() {
return "Data{" +
"distance=" + getDistance() +
", distance_overall=" + getDistanceOverall() +
", speed=" + getSpeed() +
'}';
}
}
public record Data(Distance distance, Distance distanceOverall, Speed speed) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ public Pair<Cadence, String> getCadence() {
}

public Pair<Speed, String> getSpeed() {
if (cyclingDistanceSpeed != null && cyclingDistanceSpeed.hasValue() && cyclingDistanceSpeed.getValue().getSpeed() != null) {
return new Pair<>(cyclingDistanceSpeed.getValue().getSpeed(), cyclingDistanceSpeed.getSensorNameOrAddress());
if (cyclingDistanceSpeed != null && cyclingDistanceSpeed.hasValue() && cyclingDistanceSpeed.getValue().speed() != null) {
return new Pair<>(cyclingDistanceSpeed.getValue().speed(), cyclingDistanceSpeed.getSensorNameOrAddress());
}

if (runningDistanceSpeedCadence != null && runningDistanceSpeedCadence.hasValue() && runningDistanceSpeedCadence.getValue().speed() != null) {
Expand Down Expand Up @@ -143,7 +143,7 @@ public void fillTrackPoint(TrackPoint trackPoint) {
}

if (cyclingDistanceSpeed != null && cyclingDistanceSpeed.hasValue()) {
trackPoint.setSensorDistance(cyclingDistanceSpeed.getValue().getDistanceOverall());
trackPoint.setSensorDistance(cyclingDistanceSpeed.getValue().distanceOverall());
}

if (cyclingPower != null && cyclingPower.hasValue()) {
Expand Down

0 comments on commit d47fa27

Please sign in to comment.