Removed Waypoint default constructor used by testing.

This avoids a null check for Waypoint.getLocation().
This commit is contained in:
Dennis Guse
2020-04-14 07:12:56 +02:00
parent 1a86db0a8b
commit ec39e67a09
8 changed files with 157 additions and 174 deletions
@@ -1,6 +1,9 @@
package de.dennisguse.opentracks.content.data;
import android.location.Location;
import android.util.Pair;
import de.dennisguse.opentracks.content.provider.ContentProviderUtils;
public class TestDataUtil {
@@ -8,22 +11,40 @@ public class TestDataUtil {
public static final double INITIAL_LONGITUDE = -57.0;
public static final double ALTITUDE_INTERVAL = 2.5;
/**
* Create a track without any trackPoints.
*/
public static Track createTrack(long trackId) {
Track track = new Track();
track.setId(trackId);
track.setName("Test: " + trackId);
return track;
}
/**
* Simulates a track which is used for testing.
*
* @param id the id of the track
* @param numPoints the location number in the track
* @return the simulated track
* @param trackId the trackId of the track
* @param numPoints the trackPoints number in the track
*/
@Deprecated //TODO Does not store the data in the db.
public static Track getTrack(long id, int numPoints) {
Track track = new Track();
track.setId(id);
track.setName("Test: " + id);
public static Pair<Track, TrackPoint[]> createTrack(long trackId, int numPoints) {
Track track = createTrack(trackId);
TrackPoint[] trackPoints = new TrackPoint[numPoints];
for (int i = 0; i < numPoints; i++) {
track.addTrackPoint(createTrackPoint(i));
trackPoints[i] = (createTrackPoint(i));
}
return track;
return new Pair<>(track, trackPoints);
}
public static Track createTrackAndInsert(ContentProviderUtils contentProviderUtils, long trackId, int numPoints) {
Pair<Track, TrackPoint[]> pair = createTrack(trackId, numPoints);
insertTrackWithLocations(contentProviderUtils, pair.first, pair.second);
return pair.first;
}
/**
@@ -41,4 +62,15 @@ public class TestDataUtil {
location.setTime(i + 1);
return new TrackPoint(location);
}
/**
* Inserts a track with locations into the database.
*
* @param track track to be inserted
* @param trackPoints trackPoints to be inserted
*/
public static void insertTrackWithLocations(ContentProviderUtils contentProviderUtils, Track track, TrackPoint[] trackPoints) {
contentProviderUtils.insertTrack(track);
contentProviderUtils.bulkInsertTrackPoint(trackPoints, trackPoints.length, track.getId());
}
}