Tests: create TrackPoint instead of Location.

This commit is contained in:
Dennis Guse
2021-06-30 22:33:40 +02:00
parent 3cb04a1ca0
commit 5899235b2b
6 changed files with 39 additions and 51 deletions
@@ -1,7 +1,5 @@
package de.dennisguse.opentracks.content.data; package de.dennisguse.opentracks.content.data;
import android.location.Location;
import org.junit.Test; import org.junit.Test;
import java.time.Instant; import java.time.Instant;
@@ -31,15 +29,13 @@ public class TrackPointTest {
@Test @Test
public void distanceToPrevious() { public void distanceToPrevious() {
Location l1 = new Location("test"); TrackPoint tp1 = new TrackPoint(TrackPoint.Type.TRACKPOINT)
l1.setLatitude(0); .setLatitude(0)
l1.setLongitude(0.0001); .setLongitude(0.0001);
TrackPoint tp1 = new TrackPoint(l1);
Location l2 = new Location("test"); TrackPoint tp2 = new TrackPoint(TrackPoint.Type.TRACKPOINT)
l2.setLatitude(0); .setLatitude(0)
l2.setLongitude(0.0002); .setLongitude(0.0002);
TrackPoint tp2 = new TrackPoint(l2);
// without sensor distance // without sensor distance
assertEquals(11.13, tp2.distanceToPrevious(tp1).toM(), 0.01); assertEquals(11.13, tp2.distanceToPrevious(tp1).toM(), 0.01);
@@ -135,12 +135,12 @@ public class CustomContentProviderUtilsTest {
List<TrackPoint> trackPoints = new ArrayList<>(numPoints); List<TrackPoint> trackPoints = new ArrayList<>(numPoints);
for (int i = 0; i < numPoints; ++i) { for (int i = 0; i < numPoints; ++i) {
Location loc = new Location("test"); TrackPoint trackPoint = new TrackPoint(TrackPoint.Type.TRACKPOINT)
loc.setLatitude(37.0 + (double) i / 10000.0); .setLatitude(37.0 + (double) i / 10000.0)
loc.setLongitude(57.0 - (double) i / 10000.0); .setLongitude(57.0 - (double) i / 10000.0)
loc.setAccuracy((float) i / 100.0f); .setAccuracy((float) i / 100.0f)
loc.setAltitude(i * 2.5); .setAltitude(i * 2.5);
trackPoints.add(new TrackPoint(loc)); trackPoints.add(trackPoint);
} }
contentProviderUtils.bulkInsertTrackPoint(trackPoints, id); contentProviderUtils.bulkInsertTrackPoint(trackPoints, id);
@@ -1252,7 +1252,7 @@ public class CustomContentProviderUtilsTest {
@Test @Test
public void testGetSensorStats_veryLongActivity12h() { public void testGetSensorStats_veryLongActivity12h() {
testGetSensorStats_randomData(43200 / 6, false); testGetSensorStats_randomData(43200 / 6, false);
} }
@Test @Test
@@ -16,8 +16,9 @@
package de.dennisguse.opentracks.fragments; package de.dennisguse.opentracks.fragments;
import android.location.Location; import java.time.Instant;
import de.dennisguse.opentracks.content.data.Speed;
import de.dennisguse.opentracks.content.data.TrackPoint; import de.dennisguse.opentracks.content.data.TrackPoint;
/** /**
@@ -29,11 +30,10 @@ public class TrackStubUtils {
public static final double INITIAL_ALTITUDE = 22; public static final double INITIAL_ALTITUDE = 22;
public static final long INITIAL_TIME = 1000L; public static final long INITIAL_TIME = 1000L;
private static final String LOCATION_PROVIDER = "gps";
private static final double INITIAL_LATITUDE = 22; private static final double INITIAL_LATITUDE = 22;
private static final double INITIAL_LONGITUDE = 22; private static final double INITIAL_LONGITUDE = 22;
private static final float INITIAL_ACCURACY = 5; private static final float INITIAL_ACCURACY = 5;
private static final float INITIAL_SPEED = 10; private static final Speed INITIAL_SPEED = Speed.of(10);
private static final float INITIAL_BEARING = 3.0f; private static final float INITIAL_BEARING = 3.0f;
/** /**
@@ -51,15 +51,12 @@ public class TrackStubUtils {
* @return a SensorDataSetLocation stub. * @return a SensorDataSetLocation stub.
*/ */
private static TrackPoint createDefaultTrackPoint(double latitude, double longitude, double altitude) { private static TrackPoint createDefaultTrackPoint(double latitude, double longitude, double altitude) {
Location location = new Location(LOCATION_PROVIDER); return new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.ofEpochMilli(INITIAL_TIME))
location.setLatitude(latitude); .setLatitude(latitude)
location.setLongitude(longitude); .setLongitude(longitude)
location.setAltitude(altitude); .setAltitude(altitude)
location.setAccuracy(INITIAL_ACCURACY); .setAccuracy(INITIAL_ACCURACY)
location.setSpeed(INITIAL_SPEED); .setSpeed(INITIAL_SPEED)
location.setTime(INITIAL_TIME); //TODO This is nowadays ignored as the constructor will replace the time. .setBearing(INITIAL_BEARING);
location.setBearing(INITIAL_BEARING);
return new TrackPoint(location);
} }
} }
@@ -19,7 +19,6 @@ import android.content.ContentProvider;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.location.Location;
import android.os.IBinder; import android.os.IBinder;
import android.os.Looper; import android.os.Looper;
@@ -46,6 +45,7 @@ import java.util.concurrent.TimeoutException;
import de.dennisguse.opentracks.R; import de.dennisguse.opentracks.R;
import de.dennisguse.opentracks.content.data.Marker; import de.dennisguse.opentracks.content.data.Marker;
import de.dennisguse.opentracks.content.data.Speed;
import de.dennisguse.opentracks.content.data.TestDataUtil; import de.dennisguse.opentracks.content.data.TestDataUtil;
import de.dennisguse.opentracks.content.data.Track; import de.dennisguse.opentracks.content.data.Track;
import de.dennisguse.opentracks.content.data.TrackPoint; import de.dennisguse.opentracks.content.data.TrackPoint;
@@ -407,14 +407,12 @@ public class TrackRecordingServiceTest {
* Inserts a location and waits for 200ms. * Inserts a location and waits for 200ms.
*/ */
private static void newTrackPoint(TrackRecordingService trackRecordingService, double latitude, double longitude, float accuracy, long speed, long time) { private static void newTrackPoint(TrackRecordingService trackRecordingService, double latitude, double longitude, float accuracy, long speed, long time) {
Location location = new Location(""); TrackPoint trackPoint = new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.ofEpochMilli(time))
location.setLongitude(longitude); .setLongitude(longitude)
location.setLatitude(latitude); .setLatitude(latitude)
location.setAccuracy(accuracy); .setAccuracy(accuracy)
location.setSpeed(speed); .setSpeed(Speed.of(speed))
location.setTime(time); .setBearing(3.0f);
location.setBearing(3.0f);
TrackPoint trackPoint = new TrackPoint(location);
trackRecordingService.newTrackPoint(trackPoint, 50); trackRecordingService.newTrackPoint(trackPoint, 50);
} }
} }
@@ -3,7 +3,6 @@ package de.dennisguse.opentracks.services;
import android.content.ContentProvider; import android.content.ContentProvider;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.location.Location;
import android.os.Looper; import android.os.Looper;
import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager;
@@ -26,6 +25,7 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
import de.dennisguse.opentracks.R; import de.dennisguse.opentracks.R;
import de.dennisguse.opentracks.content.data.Speed;
import de.dennisguse.opentracks.content.data.Track; import de.dennisguse.opentracks.content.data.Track;
import de.dennisguse.opentracks.content.data.TrackPoint; import de.dennisguse.opentracks.content.data.TrackPoint;
import de.dennisguse.opentracks.content.provider.ContentProviderUtils; import de.dennisguse.opentracks.content.provider.ContentProviderUtils;
@@ -233,16 +233,14 @@ public class TrackRecordingServiceTestLooper {
assertEquals(trackId, track.getId()); assertEquals(trackId, track.getId());
// Insert a few points, markers and statistics. // Insert a few points, markers and statistics.
long startTime = System.currentTimeMillis();
for (int i = 0; i < 30; i++) { for (int i = 0; i < 30; i++) {
Location location = new Location("gps"); TrackPoint trackPoint = new TrackPoint(TrackPoint.Type.TRACKPOINT)
location.setLongitude(35.0f + i / 10.0f); .setLongitude(35.0f + i / 10.0f)
location.setLatitude(45.0f - i / 5.0f); .setLatitude(45.0f - i / 5.0f)
location.setAccuracy(5); .setAccuracy(5)
location.setSpeed(10); .setSpeed(Speed.of(10))
location.setTime(startTime + i * 10000); .setBearing(3.0f);
location.setBearing(3.0f);
TrackPoint trackPoint = new TrackPoint(location);
int prefAccuracy = PreferencesUtils.getRecordingGPSAccuracy(sharedPreferences, context); int prefAccuracy = PreferencesUtils.getRecordingGPSAccuracy(sharedPreferences, context);
service.newTrackPoint(trackPoint, prefAccuracy); service.newTrackPoint(trackPoint, prefAccuracy);
@@ -655,8 +655,7 @@ public class TrackRecordingService extends Service implements HandlerServer.Hand
altitudeSumManager.reset(); altitudeSumManager.reset();
} }
//TODO We need a copy of the SensorDataSet as data will be reset! fillWithSensorDataSet(trackPoint);
SensorDataSet sensorDataSet = fillWithSensorDataSet(trackPoint);
if (remoteSensorManager != null) { if (remoteSensorManager != null) {
remoteSensorManager.reset(); remoteSensorManager.reset();
} }