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;
import android.location.Location;
import org.junit.Test;
import java.time.Instant;
@@ -31,15 +29,13 @@ public class TrackPointTest {
@Test
public void distanceToPrevious() {
Location l1 = new Location("test");
l1.setLatitude(0);
l1.setLongitude(0.0001);
TrackPoint tp1 = new TrackPoint(l1);
TrackPoint tp1 = new TrackPoint(TrackPoint.Type.TRACKPOINT)
.setLatitude(0)
.setLongitude(0.0001);
Location l2 = new Location("test");
l2.setLatitude(0);
l2.setLongitude(0.0002);
TrackPoint tp2 = new TrackPoint(l2);
TrackPoint tp2 = new TrackPoint(TrackPoint.Type.TRACKPOINT)
.setLatitude(0)
.setLongitude(0.0002);
// without sensor distance
assertEquals(11.13, tp2.distanceToPrevious(tp1).toM(), 0.01);
@@ -135,12 +135,12 @@ public class CustomContentProviderUtilsTest {
List<TrackPoint> trackPoints = new ArrayList<>(numPoints);
for (int i = 0; i < numPoints; ++i) {
Location loc = new Location("test");
loc.setLatitude(37.0 + (double) i / 10000.0);
loc.setLongitude(57.0 - (double) i / 10000.0);
loc.setAccuracy((float) i / 100.0f);
loc.setAltitude(i * 2.5);
trackPoints.add(new TrackPoint(loc));
TrackPoint trackPoint = new TrackPoint(TrackPoint.Type.TRACKPOINT)
.setLatitude(37.0 + (double) i / 10000.0)
.setLongitude(57.0 - (double) i / 10000.0)
.setAccuracy((float) i / 100.0f)
.setAltitude(i * 2.5);
trackPoints.add(trackPoint);
}
contentProviderUtils.bulkInsertTrackPoint(trackPoints, id);
@@ -1252,7 +1252,7 @@ public class CustomContentProviderUtilsTest {
@Test
public void testGetSensorStats_veryLongActivity12h() {
testGetSensorStats_randomData(43200 / 6, false);
testGetSensorStats_randomData(43200 / 6, false);
}
@Test
@@ -16,8 +16,9 @@
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;
/**
@@ -29,11 +30,10 @@ public class TrackStubUtils {
public static final double INITIAL_ALTITUDE = 22;
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_LONGITUDE = 22;
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;
/**
@@ -51,15 +51,12 @@ public class TrackStubUtils {
* @return a SensorDataSetLocation stub.
*/
private static TrackPoint createDefaultTrackPoint(double latitude, double longitude, double altitude) {
Location location = new Location(LOCATION_PROVIDER);
location.setLatitude(latitude);
location.setLongitude(longitude);
location.setAltitude(altitude);
location.setAccuracy(INITIAL_ACCURACY);
location.setSpeed(INITIAL_SPEED);
location.setTime(INITIAL_TIME); //TODO This is nowadays ignored as the constructor will replace the time.
location.setBearing(INITIAL_BEARING);
return new TrackPoint(location);
return new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.ofEpochMilli(INITIAL_TIME))
.setLatitude(latitude)
.setLongitude(longitude)
.setAltitude(altitude)
.setAccuracy(INITIAL_ACCURACY)
.setSpeed(INITIAL_SPEED)
.setBearing(INITIAL_BEARING);
}
}
@@ -19,7 +19,6 @@ import android.content.ContentProvider;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.location.Location;
import android.os.IBinder;
import android.os.Looper;
@@ -46,6 +45,7 @@ import java.util.concurrent.TimeoutException;
import de.dennisguse.opentracks.R;
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.Track;
import de.dennisguse.opentracks.content.data.TrackPoint;
@@ -407,14 +407,12 @@ public class TrackRecordingServiceTest {
* Inserts a location and waits for 200ms.
*/
private static void newTrackPoint(TrackRecordingService trackRecordingService, double latitude, double longitude, float accuracy, long speed, long time) {
Location location = new Location("");
location.setLongitude(longitude);
location.setLatitude(latitude);
location.setAccuracy(accuracy);
location.setSpeed(speed);
location.setTime(time);
location.setBearing(3.0f);
TrackPoint trackPoint = new TrackPoint(location);
TrackPoint trackPoint = new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.ofEpochMilli(time))
.setLongitude(longitude)
.setLatitude(latitude)
.setAccuracy(accuracy)
.setSpeed(Speed.of(speed))
.setBearing(3.0f);
trackRecordingService.newTrackPoint(trackPoint, 50);
}
}
@@ -3,7 +3,6 @@ package de.dennisguse.opentracks.services;
import android.content.ContentProvider;
import android.content.Context;
import android.content.SharedPreferences;
import android.location.Location;
import android.os.Looper;
import androidx.preference.PreferenceManager;
@@ -26,6 +25,7 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
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.TrackPoint;
import de.dennisguse.opentracks.content.provider.ContentProviderUtils;
@@ -233,16 +233,14 @@ public class TrackRecordingServiceTestLooper {
assertEquals(trackId, track.getId());
// Insert a few points, markers and statistics.
long startTime = System.currentTimeMillis();
for (int i = 0; i < 30; i++) {
Location location = new Location("gps");
location.setLongitude(35.0f + i / 10.0f);
location.setLatitude(45.0f - i / 5.0f);
location.setAccuracy(5);
location.setSpeed(10);
location.setTime(startTime + i * 10000);
location.setBearing(3.0f);
TrackPoint trackPoint = new TrackPoint(location);
TrackPoint trackPoint = new TrackPoint(TrackPoint.Type.TRACKPOINT)
.setLongitude(35.0f + i / 10.0f)
.setLatitude(45.0f - i / 5.0f)
.setAccuracy(5)
.setSpeed(Speed.of(10))
.setBearing(3.0f);
int prefAccuracy = PreferencesUtils.getRecordingGPSAccuracy(sharedPreferences, context);
service.newTrackPoint(trackPoint, prefAccuracy);