Skip to content
This repository was archived by the owner on Aug 24, 2025. It is now read-only.

Commit cd7bf36

Browse files
committed
TrackRecordingService: add integration tests.
1 parent ab07d3b commit cd7bf36

7 files changed

Lines changed: 432 additions & 402 deletions

File tree

src/androidTest/java/de/dennisguse/opentracks/io/file/importer/TrackPointAssert.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
public class TrackPointAssert {
1010

11-
private boolean assertTime = true;
1211
private boolean assertAccuracy = true;
1312

1413
private double delta = 0.001;
@@ -17,10 +16,7 @@ public TrackPointAssert() {
1716
}
1817

1918
public void assertEquals(TrackPoint expected, TrackPoint actual) {
20-
Assert.assertNotNull(actual.getTime());
21-
if (assertTime) {
22-
Assert.assertEquals(expected.getTime(), actual.getTime());
23-
}
19+
Assert.assertEquals(expected.getTime(), actual.getTime());
2420

2521
Assert.assertEquals(expected.getType(), actual.getType());
2622

@@ -100,12 +96,6 @@ public void assertEquals(List<TrackPoint> expected, List<TrackPoint> actual) {
10096
}
10197
}
10298

103-
@Deprecated //Try to mock time instead.
104-
public TrackPointAssert ignoreTime() {
105-
this.assertTime = false;
106-
return this;
107-
}
108-
10999
public TrackPointAssert noAccuracy() {
110100
this.assertAccuracy = false;
111101
return this;

src/androidTest/java/de/dennisguse/opentracks/services/TrackRecordingServiceTestRecording.java

Lines changed: 391 additions & 355 deletions
Large diffs are not rendered by default.

src/androidTest/java/de/dennisguse/opentracks/services/TrackRecordingServiceTestUtils.java

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@
22

33
import android.content.Context;
44
import android.content.Intent;
5+
import android.location.Location;
56

67
import androidx.test.rule.ServiceTestRule;
78

89
import java.time.Clock;
9-
import java.time.Instant;
1010
import java.util.concurrent.TimeoutException;
1111

12-
import de.dennisguse.opentracks.content.data.Distance;
13-
import de.dennisguse.opentracks.content.data.Speed;
14-
import de.dennisguse.opentracks.content.data.TrackPoint;
12+
import de.dennisguse.opentracks.services.handlers.TrackPointCreator;
1513
import de.dennisguse.opentracks.services.sensors.BluetoothRemoteSensorManager;
1614
import de.dennisguse.opentracks.settings.PreferencesUtils;
1715

@@ -35,18 +33,15 @@ public static void resetService(ServiceTestRule mServiceRule, Context context) t
3533
service.sharedPreferenceChangeListener.onSharedPreferenceChanged(null, null);
3634
}
3735

38-
static void newTrackPoint(TrackRecordingService trackRecordingService, double latitude, double longitude, float accuracy, long speed) {
39-
newTrackPoint(trackRecordingService, latitude, longitude, accuracy, speed, System.currentTimeMillis());
40-
}
41-
42-
static void newTrackPoint(TrackRecordingService trackRecordingService, double latitude, double longitude, float accuracy, long speed, long time) {
43-
TrackPoint trackPoint = new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.ofEpochMilli(time))
44-
.setLongitude(longitude)
45-
.setLatitude(latitude)
46-
.setHorizontalAccuracy(Distance.of(accuracy))
47-
.setSpeed(Speed.of(speed))
48-
.setBearing(3.0f);
36+
static void sendGPSLocation(TrackPointCreator trackPointCreator, String time, double latitude, double longitude, float accuracy, long speed) {
37+
Location location = new Location("mock");
38+
location.setTime(1L); // Should be ignored anyhow.
39+
location.setLatitude(latitude);
40+
location.setLongitude(longitude);
41+
location.setAccuracy(accuracy);
42+
location.setSpeed(speed);
4943

50-
trackRecordingService.getTrackPointCreator().onNewTrackPoint(trackPoint);
44+
trackPointCreator.setClock(time);
45+
trackPointCreator.getGpsHandler().onLocationChanged(location);
5146
}
5247
}

src/main/java/de/dennisguse/opentracks/content/data/TrackPoint.java

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -415,27 +415,25 @@ public TrackPoint setPower(Float power) {
415415
return this;
416416
}
417417

418-
@NonNull
419418
@Override
420419
public String toString() {
421-
String result = "time=" + getTime() + " (type=" + getType() + ")";
422-
if (hasLocation()) {
423-
result += ": lat=" + getLatitude() + " lng=" + getLongitude() + " alt=" + getAltitude();
424-
}
425-
if (hasHorizontalAccuracy()) {
426-
result += " acc=" + getHorizontalAccuracy();
427-
}
428-
if (hasSensorDistance()) {
429-
result += " distance=" + getSensorDistance();
430-
}
431-
if (hasAltitudeGain()) {
432-
result += " altitudeGain= " + getAltitudeGain();
433-
}
434-
if (hasAltitudeLoss()) {
435-
result += " altitudeLoss= " + getAltitudeLoss();
436-
}
437-
438-
return result;
420+
return "TrackPoint{" +
421+
"id=" + id +
422+
", time=" + time +
423+
", latitude=" + latitude +
424+
", longitude=" + longitude +
425+
", horizontalAccuracy=" + horizontalAccuracy +
426+
", altitude=" + altitude +
427+
", speed=" + speed +
428+
", bearing=" + bearing +
429+
", sensorDistance=" + sensorDistance +
430+
", type=" + type +
431+
", heartRate_bpm=" + heartRate_bpm +
432+
", cadence_rpm=" + cadence_rpm +
433+
", power=" + power +
434+
", altitudeGain_m=" + altitudeGain_m +
435+
", altitudeLoss_m=" + altitudeLoss_m +
436+
'}';
439437
}
440438

441439
public static class Id {

src/main/java/de/dennisguse/opentracks/services/handlers/TrackPointCreator.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,12 @@ public void setAltitudeSumManager(AltitudeSumManager altitudeSumManager) {
178178
this.altitudeSumManager = altitudeSumManager;
179179
}
180180

181+
@Deprecated
182+
@VisibleForTesting
183+
public BluetoothRemoteSensorManager getRemoteSensorManager() {
184+
return remoteSensorManager;
185+
}
186+
181187
@Deprecated
182188
@VisibleForTesting
183189
public void setRemoteSensorManager(BluetoothRemoteSensorManager remoteSensorManager) {

src/main/java/de/dennisguse/opentracks/settings/PreferencesUtils.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,11 @@ public static void setString(int keyId, String value) {
168168
editor.apply();
169169
}
170170

171+
@VisibleForTesting
172+
public static void setString(int keyId, int valueId) {
173+
setString(keyId, resources.getString(valueId));
174+
}
175+
171176
static void setInt(int keyId, int value) {
172177
Editor editor = sharedPreferences.edit();
173178
editor.putInt(getKey(keyId), value);

src/main/java/de/dennisguse/opentracks/stats/TrackStatistics.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public TrackStatistics(TrackStatistics other) {
7878
}
7979

8080
@VisibleForTesting
81-
public TrackStatistics(String startTime, String stopTime, int totalDistance_m, int totalTime_s, int movingTime_s, float maxSpeed_mps, Float totalAltitudeGain_m, Float totalAltitudeLoss_m) {
81+
public TrackStatistics(String startTime, String stopTime, double totalDistance_m, int totalTime_s, int movingTime_s, float maxSpeed_mps, Float totalAltitudeGain_m, Float totalAltitudeLoss_m) {
8282
this.startTime = Instant.parse(startTime);
8383
this.stopTime = Instant.parse(stopTime);
8484
this.totalDistance = Distance.of(totalDistance_m);

0 commit comments

Comments
 (0)