mirror of
https://codeberg.org/OpenTracksApp/OpenTracks.git
synced 2026-10-02 17:43:06 +02:00
TrackRecordingService: add integration tests.
This commit is contained in:
+1
-11
@@ -8,7 +8,6 @@ import de.dennisguse.opentracks.content.data.TrackPoint;
|
||||
|
||||
public class TrackPointAssert {
|
||||
|
||||
private boolean assertTime = true;
|
||||
private boolean assertAccuracy = true;
|
||||
|
||||
private double delta = 0.001;
|
||||
@@ -17,10 +16,7 @@ public class TrackPointAssert {
|
||||
}
|
||||
|
||||
public void assertEquals(TrackPoint expected, TrackPoint actual) {
|
||||
Assert.assertNotNull(actual.getTime());
|
||||
if (assertTime) {
|
||||
Assert.assertEquals(expected.getTime(), actual.getTime());
|
||||
}
|
||||
Assert.assertEquals(expected.getTime(), actual.getTime());
|
||||
|
||||
Assert.assertEquals(expected.getType(), actual.getType());
|
||||
|
||||
@@ -100,12 +96,6 @@ public class TrackPointAssert {
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated //Try to mock time instead.
|
||||
public TrackPointAssert ignoreTime() {
|
||||
this.assertTime = false;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TrackPointAssert noAccuracy() {
|
||||
this.assertAccuracy = false;
|
||||
return this;
|
||||
|
||||
+434
-398
File diff suppressed because it is too large
Load Diff
+11
-16
@@ -2,16 +2,14 @@ package de.dennisguse.opentracks.services;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.location.Location;
|
||||
|
||||
import androidx.test.rule.ServiceTestRule;
|
||||
|
||||
import java.time.Clock;
|
||||
import java.time.Instant;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import de.dennisguse.opentracks.content.data.Distance;
|
||||
import de.dennisguse.opentracks.content.data.Speed;
|
||||
import de.dennisguse.opentracks.content.data.TrackPoint;
|
||||
import de.dennisguse.opentracks.services.handlers.TrackPointCreator;
|
||||
import de.dennisguse.opentracks.services.sensors.BluetoothRemoteSensorManager;
|
||||
import de.dennisguse.opentracks.settings.PreferencesUtils;
|
||||
|
||||
@@ -35,18 +33,15 @@ public class TrackRecordingServiceTestUtils {
|
||||
service.sharedPreferenceChangeListener.onSharedPreferenceChanged(null, null);
|
||||
}
|
||||
|
||||
static void newTrackPoint(TrackRecordingService trackRecordingService, double latitude, double longitude, float accuracy, long speed) {
|
||||
newTrackPoint(trackRecordingService, latitude, longitude, accuracy, speed, System.currentTimeMillis());
|
||||
}
|
||||
static void sendGPSLocation(TrackPointCreator trackPointCreator, String time, double latitude, double longitude, float accuracy, long speed) {
|
||||
Location location = new Location("mock");
|
||||
location.setTime(1L); // Should be ignored anyhow.
|
||||
location.setLatitude(latitude);
|
||||
location.setLongitude(longitude);
|
||||
location.setAccuracy(accuracy);
|
||||
location.setSpeed(speed);
|
||||
|
||||
static void newTrackPoint(TrackRecordingService trackRecordingService, double latitude, double longitude, float accuracy, long speed, long time) {
|
||||
TrackPoint trackPoint = new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.ofEpochMilli(time))
|
||||
.setLongitude(longitude)
|
||||
.setLatitude(latitude)
|
||||
.setHorizontalAccuracy(Distance.of(accuracy))
|
||||
.setSpeed(Speed.of(speed))
|
||||
.setBearing(3.0f);
|
||||
|
||||
trackRecordingService.getTrackPointCreator().onNewTrackPoint(trackPoint);
|
||||
trackPointCreator.setClock(time);
|
||||
trackPointCreator.getGpsHandler().onLocationChanged(location);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -415,27 +415,25 @@ public class TrackPoint {
|
||||
return this;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String toString() {
|
||||
String result = "time=" + getTime() + " (type=" + getType() + ")";
|
||||
if (hasLocation()) {
|
||||
result += ": lat=" + getLatitude() + " lng=" + getLongitude() + " alt=" + getAltitude();
|
||||
}
|
||||
if (hasHorizontalAccuracy()) {
|
||||
result += " acc=" + getHorizontalAccuracy();
|
||||
}
|
||||
if (hasSensorDistance()) {
|
||||
result += " distance=" + getSensorDistance();
|
||||
}
|
||||
if (hasAltitudeGain()) {
|
||||
result += " altitudeGain= " + getAltitudeGain();
|
||||
}
|
||||
if (hasAltitudeLoss()) {
|
||||
result += " altitudeLoss= " + getAltitudeLoss();
|
||||
}
|
||||
|
||||
return result;
|
||||
return "TrackPoint{" +
|
||||
"id=" + id +
|
||||
", time=" + time +
|
||||
", latitude=" + latitude +
|
||||
", longitude=" + longitude +
|
||||
", horizontalAccuracy=" + horizontalAccuracy +
|
||||
", altitude=" + altitude +
|
||||
", speed=" + speed +
|
||||
", bearing=" + bearing +
|
||||
", sensorDistance=" + sensorDistance +
|
||||
", type=" + type +
|
||||
", heartRate_bpm=" + heartRate_bpm +
|
||||
", cadence_rpm=" + cadence_rpm +
|
||||
", power=" + power +
|
||||
", altitudeGain_m=" + altitudeGain_m +
|
||||
", altitudeLoss_m=" + altitudeLoss_m +
|
||||
'}';
|
||||
}
|
||||
|
||||
public static class Id {
|
||||
|
||||
@@ -178,6 +178,12 @@ public class TrackPointCreator implements BluetoothRemoteSensorManager.SensorDat
|
||||
this.altitudeSumManager = altitudeSumManager;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@VisibleForTesting
|
||||
public BluetoothRemoteSensorManager getRemoteSensorManager() {
|
||||
return remoteSensorManager;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@VisibleForTesting
|
||||
public void setRemoteSensorManager(BluetoothRemoteSensorManager remoteSensorManager) {
|
||||
|
||||
@@ -168,6 +168,11 @@ public class PreferencesUtils {
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public static void setString(int keyId, int valueId) {
|
||||
setString(keyId, resources.getString(valueId));
|
||||
}
|
||||
|
||||
static void setInt(int keyId, int value) {
|
||||
Editor editor = sharedPreferences.edit();
|
||||
editor.putInt(getKey(keyId), value);
|
||||
|
||||
@@ -78,7 +78,7 @@ public class TrackStatistics {
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public TrackStatistics(String startTime, String stopTime, int totalDistance_m, int totalTime_s, int movingTime_s, float maxSpeed_mps, Float totalAltitudeGain_m, Float totalAltitudeLoss_m) {
|
||||
public TrackStatistics(String startTime, String stopTime, double totalDistance_m, int totalTime_s, int movingTime_s, float maxSpeed_mps, Float totalAltitudeGain_m, Float totalAltitudeLoss_m) {
|
||||
this.startTime = Instant.parse(startTime);
|
||||
this.stopTime = Instant.parse(stopTime);
|
||||
this.totalDistance = Distance.of(totalDistance_m);
|
||||
|
||||
Reference in New Issue
Block a user