Tests: created TrackPointAssert to unify verification.

This commit is contained in:
Dennis Guse
2021-06-27 21:07:38 +02:00
parent 4c8e87614f
commit 1f83b71336
6 changed files with 270 additions and 199 deletions
@@ -5,7 +5,6 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Looper;
import android.util.Log;
import androidx.preference.PreferenceManager;
import androidx.test.core.app.ApplicationProvider;
@@ -186,7 +185,9 @@ public class ExportImportTest {
assertEquals(track.getIcon(), importedTrack.getIcon());
// 2. trackpoints
assertTrackpoints(trackPoints, true, true, true, true, true, true);
TrackPointAssert a = new TrackPointAssert()
.noAccuracy();
a.assertEquals(trackPoints, TestDataUtil.getTrackPoints(contentProviderUtils, importTrackId));
// 2. trackstatistics
assertTrackStatistics(false, true, true);
@@ -225,7 +226,9 @@ public class ExportImportTest {
assertEquals(track.getIcon(), importedTrack.getIcon());
// 2. trackpoints
assertTrackpoints(trackPoints, true, true, true, true, true, true);
TrackPointAssert a = new TrackPointAssert()
.noAccuracy();
a.assertEquals(trackPoints, TestDataUtil.getTrackPoints(contentProviderUtils, importTrackId));
// 2. trackstatistics
assertTrackStatistics(false, true, true);
@@ -298,7 +301,8 @@ public class ExportImportTest {
trackPointsWithCoordinates.get(0).setType(TrackPoint.Type.SEGMENT_START_AUTOMATIC);
trackPointsWithCoordinates.get(3).setType(TrackPoint.Type.SEGMENT_START_AUTOMATIC);
assertTrackpoints(trackPointsWithCoordinates, true, true, true, true, true, false);
TrackPointAssert a = new TrackPointAssert();
a.assertEquals(trackPointsWithCoordinates, TestDataUtil.getTrackPoints(contentProviderUtils, importTrackId));
// 3. trackstatistics
assertTrackStatistics(true, true, false);
@@ -354,62 +358,6 @@ public class ExportImportTest {
}
}
private void assertTrackpoints(List<TrackPoint> trackPoints, boolean verifyPower, boolean verifyHeartrate, boolean verifyCadence, boolean verifyAltitudeGain, boolean verifyAltitudeLoss, boolean verifyDistance) {
List<TrackPoint> importedTrackPoints = TestDataUtil.getTrackPoints(contentProviderUtils, importTrackId);
assertEquals(trackPoints.size(), importedTrackPoints.size());
for (int i = 0; i < trackPoints.size(); i++) {
TrackPoint trackPoint = trackPoints.get(i);
TrackPoint importedTrackPoint = importedTrackPoints.get(i);
assertEquals(trackPoint.getTime(), importedTrackPoint.getTime());
TrackPoint.Type type = trackPoint.getType();
Log.e(TAG, "" + importedTrackPoint.getType().equals(type));
assertEquals("" + i, type, importedTrackPoint.getType());
// TODO Not exported for GPX/KML
// assertEquals(trackPoint.getAccuracy(), importedTrackPoint.getAccuracy(), 0.01);
assertEquals("" + i, trackPoint.hasLocation(), importedTrackPoint.hasLocation());
if (trackPoint.hasLocation()) {
assertEquals("" + i, trackPoint.getLatitude(), importedTrackPoint.getLatitude(), 0.001);
assertEquals("" + i, trackPoint.getLongitude(), importedTrackPoint.getLongitude(), 0.001);
}
assertEquals("" + i, trackPoint.hasSpeed(), importedTrackPoint.hasSpeed());
if (trackPoint.hasSpeed()) {
assertEquals("" + i, trackPoint.getSpeed().toMPS(), importedTrackPoint.getSpeed().toMPS(), 0.001);
}
assertEquals("" + i, trackPoint.hasAltitude(), importedTrackPoint.hasAltitude());
if (trackPoint.hasAltitude()) {
assertEquals("" + i, trackPoint.getAltitude().toM(), importedTrackPoint.getAltitude().toM(), 0.001);
}
if (type.equals(TrackPoint.Type.SEGMENT_START_MANUAL) || type.equals(TrackPoint.Type.SEGMENT_END_MANUAL)) {
//TODO REMOVE
continue;
}
if (verifyHeartrate) {
assertEquals("" + i, trackPoint.getHeartRate_bpm(), importedTrackPoint.getHeartRate_bpm(), 0.01);
}
if (verifyCadence) {
assertEquals("" + i, trackPoint.getCyclingCadence_rpm(), importedTrackPoint.getCyclingCadence_rpm(), 0.01);
}
if (verifyPower) {
assertEquals("" + i, trackPoint.getPower(), importedTrackPoint.getPower(), 0.01);
}
if (verifyAltitudeGain) {
assertEquals(trackPoint.getAltitudeGain(), importedTrackPoint.getAltitudeGain(), 0.01);
}
if (verifyAltitudeLoss) {
assertEquals(trackPoint.getAltitudeLoss(), importedTrackPoint.getAltitudeLoss(), 0.01);
}
if (verifyDistance) {
assertEquals(trackPoint.getSensorDistance(), importedTrackPoint.getSensorDistance());
}
}
}
private void assertTrackStatistics(boolean isGpx, boolean verifyAltitudeGainAndLoss, boolean verifyDistance) {
Track importedTrack = contentProviderUtils.getTrack(importTrackId);
@@ -21,10 +21,8 @@ import de.dennisguse.opentracks.content.data.TestDataUtil;
import de.dennisguse.opentracks.content.data.Track;
import de.dennisguse.opentracks.content.data.TrackPoint;
import de.dennisguse.opentracks.content.provider.ContentProviderUtils;
import de.dennisguse.opentracks.util.StringUtils;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
/**
@@ -80,31 +78,16 @@ public class GPXImportTest {
assertEquals(6, importedTrackPoints.size());
// first segment
assertTrackpoint(importedTrackPoints.get(0), TrackPoint.Type.SEGMENT_START_AUTOMATIC, "2021-01-07T21:51:59.179Z", 14.0, 3.0, 10.0);
assertTrackpoint(importedTrackPoints.get(1), TrackPoint.Type.TRACKPOINT, "2021-01-07T21:52:00.653Z", 14.001, 3.0, 10.0);
assertTrackpoint(importedTrackPoints.get(2), TrackPoint.Type.TRACKPOINT, "2021-01-07T21:52:01.010Z", 14.002, 3.0, 10.0);
assertTrackpoint(importedTrackPoints.get(3), TrackPoint.Type.SEGMENT_END_MANUAL, "2021-01-07T21:52:02.658Z", null, null, null);
TrackPointAssert a = new TrackPointAssert();
a.assertEquals(List.of(
a.expect(TrackPoint.Type.SEGMENT_START_AUTOMATIC, "2021-01-07T21:51:59.179Z", 14.0, 3.0, 10.0),
a.expect(TrackPoint.Type.TRACKPOINT, "2021-01-07T21:52:00.653Z", 14.001, 3.0, 10.0),
a.expect(TrackPoint.Type.TRACKPOINT, "2021-01-07T21:52:01.010Z", 14.002, 3.0, 10.0),
a.expect(TrackPoint.Type.SEGMENT_END_MANUAL, "2021-01-07T21:52:02.658Z"),
// created resume trackpoint with time of next valid trackpoint
assertTrackpoint(importedTrackPoints.get(4), TrackPoint.Type.SEGMENT_START_MANUAL, "2021-01-07T21:52:03.873Z", null, null, null);
assertTrackpoint(importedTrackPoints.get(5), TrackPoint.Type.TRACKPOINT, "2021-01-07T21:52:04.103Z", 14.003, 3.0, 10.0);
}
static void assertTrackpoint(final TrackPoint trackPoint, final TrackPoint.Type type, final String when, final Double longitude, final Double latitude, final Double altitude) {
assertEquals(StringUtils.parseTime(when), trackPoint.getTime());
assertEquals(type, trackPoint.getType());
if (longitude == null) {
assertFalse(trackPoint.hasLocation());
} else {
assertEquals(latitude, (Double) trackPoint.getLatitude());
assertEquals(longitude, (Double) trackPoint.getLongitude());
}
if (altitude == null) {
assertFalse(trackPoint.hasAltitude());
} else {
assertEquals(altitude, (Double) trackPoint.getAltitude().toM());
}
// created resume trackpoint with time of next valid trackpoint
a.expect(TrackPoint.Type.SEGMENT_START_MANUAL, "2021-01-07T21:52:03.873Z"),
a.expect(TrackPoint.Type.TRACKPOINT, "2021-01-07T21:52:04.103Z", 14.003, 3.0, 10.0)
), importedTrackPoints);
}
}
@@ -78,13 +78,14 @@ public class KMLImportTest {
// 3. trackpoints
List<TrackPoint> importedTrackPoints = TestDataUtil.getTrackPoints(contentProviderUtils, importTrackId);
assertEquals(5, importedTrackPoints.size());
GPXImportTest.assertTrackpoint(importedTrackPoints.get(0), TrackPoint.Type.SEGMENT_START_MANUAL, "2021-05-29T18:06:21.767Z", null, null, null);
GPXImportTest.assertTrackpoint(importedTrackPoints.get(1), TrackPoint.Type.TRACKPOINT, "2021-05-29T18:06:22.042Z", 14.0, 3.0, 10.0);
GPXImportTest.assertTrackpoint(importedTrackPoints.get(2), TrackPoint.Type.TRACKPOINT, "2021-05-29T18:06:22.192Z", 14.001, 3.0, 10.0);
GPXImportTest.assertTrackpoint(importedTrackPoints.get(3), TrackPoint.Type.TRACKPOINT, "2021-05-29T18:06:22.318Z", 14.002, 3.0, 10.0);
GPXImportTest.assertTrackpoint(importedTrackPoints.get(4), TrackPoint.Type.SEGMENT_END_MANUAL, "2021-05-29T18:06:22.512Z", null, null, null);
TrackPointAssert a = new TrackPointAssert();
a.assertEquals(List.of(
a.expect(TrackPoint.Type.SEGMENT_START_MANUAL, "2021-05-29T18:06:21.767Z"),
a.expect(TrackPoint.Type.TRACKPOINT, "2021-05-29T18:06:22.042Z", 14.0, 3.0, 10.0),
a.expect(TrackPoint.Type.TRACKPOINT, "2021-05-29T18:06:22.192Z", 14.001, 3.0, 10.0),
a.expect(TrackPoint.Type.TRACKPOINT, "2021-05-29T18:06:22.318Z", 14.002, 3.0, 10.0),
a.expect(TrackPoint.Type.SEGMENT_END_MANUAL, "2021-05-29T18:06:22.512Z")
), importedTrackPoints);
}
/**
@@ -115,10 +116,12 @@ public class KMLImportTest {
// 3. trackpoints
List<TrackPoint> importedTrackPoints = TestDataUtil.getTrackPoints(contentProviderUtils, importTrackId);
assertEquals(2, importedTrackPoints.size());
GPXImportTest.assertTrackpoint(importedTrackPoints.get(0), TrackPoint.Type.TRACKPOINT, "2021-05-29T18:06:21.767Z", 14.0, 3.0, 10.0);
GPXImportTest.assertTrackpoint(importedTrackPoints.get(1), TrackPoint.Type.SEGMENT_START_MANUAL, "2021-05-29T18:06:22.042Z", null, null, null);
TrackPointAssert a = new TrackPointAssert();
a.assertEquals(List.of(
a.expect(TrackPoint.Type.TRACKPOINT, "2021-05-29T18:06:21.767Z", 14.0, 3.0, 10.0),
a.expect(TrackPoint.Type.SEGMENT_START_MANUAL, "2021-05-29T18:06:22.042Z")
), importedTrackPoints);
}
/**
@@ -150,17 +153,25 @@ public class KMLImportTest {
// 3. trackpoints
List<TrackPoint> importedTrackPoints = TestDataUtil.getTrackPoints(contentProviderUtils, importTrackId);
assertEquals(6, importedTrackPoints.size());
// first 3 trackpoints
GPXImportTest.assertTrackpoint(importedTrackPoints.get(0), TrackPoint.Type.SEGMENT_START_AUTOMATIC, "2020-11-28T17:06:22.401Z", 1.234156, 12.340097, 469.286376953125);
GPXImportTest.assertTrackpoint(importedTrackPoints.get(1), TrackPoint.Type.TRACKPOINT, "2020-11-28T17:06:25.448Z", 1.23415, 12.340036, 439.1626281738281);
GPXImportTest.assertTrackpoint(importedTrackPoints.get(2), TrackPoint.Type.TRACKPOINT, "2020-11-28T17:06:47.888Z", 1.23405, 12.340057, 421.8070983886719);
TrackPointAssert a = new TrackPointAssert();
a.assertEquals(List.of(
// first 3 trackpoints
a.expect(TrackPoint.Type.SEGMENT_START_AUTOMATIC, "2020-11-28T17:06:22.401Z", 1.234156, 12.340097, 469.286376953125)
.setAltitudeGain(0f),
a.expect(TrackPoint.Type.TRACKPOINT, "2020-11-28T17:06:25.448Z", 1.23415, 12.340036, 439.1626281738281)
.setAltitudeGain(0f),
a.expect(TrackPoint.Type.TRACKPOINT, "2020-11-28T17:06:47.888Z", 1.23405, 12.340057, 421.8070983886719)
.setAltitudeGain(0f),
// created resume trackpoint with time of next valid trackpoint
GPXImportTest.assertTrackpoint(importedTrackPoints.get(3), TrackPoint.Type.SEGMENT_START_AUTOMATIC, "2020-11-28T17:06:55.861Z", 1.23405, 12.340057, 419.93902587890625);
GPXImportTest.assertTrackpoint(importedTrackPoints.get(4), TrackPoint.Type.TRACKPOINT, "2020-11-28T17:06:56.905Z", 1.23405, 12.340057, 419.9036560058594);
GPXImportTest.assertTrackpoint(importedTrackPoints.get(5), TrackPoint.Type.TRACKPOINT, "2020-11-28T17:07:20.870Z", 1.234046, 12.340082, 417.99432373046875);
// created resume trackpoint with time of next valid trackpoint
a.expect(TrackPoint.Type.SEGMENT_START_AUTOMATIC, "2020-11-28T17:06:55.861Z", 1.23405, 12.340057, 419.93902587890625)
.setAltitudeGain(0f),
a.expect(TrackPoint.Type.TRACKPOINT, "2020-11-28T17:06:56.905Z", 1.23405, 12.340057, 419.9036560058594)
.setAltitudeGain(0f),
a.expect(TrackPoint.Type.TRACKPOINT, "2020-11-28T17:07:20.870Z", 1.234046, 12.340082, 417.99432373046875)
.setAltitudeGain(0f)
), importedTrackPoints);
}
/**
@@ -0,0 +1,136 @@
package de.dennisguse.opentracks.io.file.importer;
import org.junit.Assert;
import java.util.List;
import de.dennisguse.opentracks.content.data.TrackPoint;
import de.dennisguse.opentracks.util.StringUtils;
public class TrackPointAssert {
private boolean assertTime = true;
private boolean assertAccuracy = true;
public TrackPointAssert() {
}
public void assertEquals(TrackPoint expected, TrackPoint actual) {
Assert.assertNotNull(actual.getTime());
if (assertTime) {
Assert.assertEquals(expected.getTime(), actual.getTime());
}
Assert.assertEquals(expected.getType(), actual.getType());
if (expected.hasLocation()) {
Assert.assertEquals(expected.hasLocation(), actual.hasLocation());
if (expected.hasLocation()) {
Assert.assertEquals(expected.getLatitude(), actual.getLatitude(), 0.001);
Assert.assertEquals(expected.getLongitude(), actual.getLongitude(), 0.001);
}
Assert.assertEquals(expected.hasAltitude(), actual.hasAltitude());
if (expected.hasAltitude()) {
Assert.assertEquals(expected.getAltitude().toM(), actual.getAltitude().toM(), 0.001);
}
}
Assert.assertEquals(expected.hasAltitudeGain(), actual.hasAltitudeGain());
if (expected.hasAltitudeGain()) {
Assert.assertEquals(expected.getAltitudeGain(), actual.getAltitudeGain(), 0.001);
}
Assert.assertEquals(expected.hasAltitudeLoss(), actual.hasAltitudeLoss());
if (expected.hasAltitudeLoss()) {
Assert.assertEquals(expected.getAltitudeLoss(), actual.getAltitudeLoss(), 0.001);
}
// TODO Speed is always computed even if none was exported, thus this assert fails for now;
// Assert.assertEquals(expected.hasSpeed(), actual.hasSpeed());
if (expected.hasSpeed()) {
Assert.assertEquals(expected.getSpeed().toMPS(), actual.getSpeed().toMPS(), 0.001);
}
if (assertAccuracy) {
Assert.assertEquals(expected.hasAccuracy(), actual.hasAccuracy());
if (expected.hasAccuracy()) {
Assert.assertEquals(expected.getAccuracy(), actual.getAccuracy(), 0.001);
}
} else {
Assert.assertFalse(actual.hasAccuracy());
}
Assert.assertEquals(expected.hasSensorDistance(), actual.hasSensorDistance());
if (expected.hasSensorDistance()) {
Assert.assertEquals(expected.getSensorDistance().toM(), actual.getSensorDistance().toM(), 0.001);
}
Assert.assertEquals(expected.hasHeartRate(), actual.hasHeartRate());
if (expected.hasHeartRate()) {
Assert.assertEquals(expected.getHeartRate_bpm(), actual.getHeartRate_bpm(), 0.001);
}
Assert.assertEquals(expected.hasPower(), actual.hasPower());
if (expected.hasPower()) {
Assert.assertEquals(expected.getPower(), actual.getPower(), 0.001);
}
Assert.assertEquals(expected.hasCyclingCadence(), actual.hasCyclingCadence());
if (expected.hasCyclingCadence()) {
Assert.assertEquals(expected.getCyclingCadence_rpm(), actual.getCyclingCadence_rpm(), 0.001);
}
}
public void assertEquals(List<TrackPoint> expected, List<TrackPoint> actual) {
Assert.assertEquals(expected.size(), actual.size());
for (int i = 0; i < expected.size(); i++) {
assertEquals(expected.get(i), actual.get(i));
}
}
public TrackPoint expect(final TrackPoint.Type type) {
return new TrackPoint(type);
}
public TrackPoint expect(final TrackPoint.Type type, float accuracy) {
TrackPoint tp = new TrackPoint(type);
tp.setAccuracy(accuracy);
return tp;
}
public TrackPoint expect(final TrackPoint.Type type, float accuracy, float heartrate) {
TrackPoint tp = new TrackPoint(type);
tp.setAccuracy(accuracy);
tp.setHeartRate_bpm(heartrate);
return tp;
}
public TrackPoint expecHeartrate(final TrackPoint.Type type, float heartrate) {
TrackPoint tp = new TrackPoint(type);
tp.setHeartRate_bpm(heartrate);
return tp;
}
public TrackPoint expect(final TrackPoint.Type type, final String when) {
return new TrackPoint(type, StringUtils.parseTime(when));
}
public TrackPoint expect(final TrackPoint.Type type, final String when, final double longitude, final double latitude, final double altitude) {
TrackPoint tp = expect(type, when);
tp.setLongitude(longitude);
tp.setLatitude(latitude);
tp.setAltitude(altitude);
return tp;
}
public TrackPointAssert ignoreTime() {
this.assertTime = false;
return this;
}
public TrackPointAssert noAccuracy() {
this.assertAccuracy = false;
return this;
}
}
@@ -4,7 +4,6 @@ import android.content.ContentProvider;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Looper;
import android.util.Pair;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
@@ -31,10 +30,10 @@ import de.dennisguse.opentracks.content.provider.ContentProviderUtils;
import de.dennisguse.opentracks.content.provider.CustomContentProvider;
import de.dennisguse.opentracks.content.sensor.SensorDataHeartRate;
import de.dennisguse.opentracks.content.sensor.SensorDataSet;
import de.dennisguse.opentracks.io.file.importer.TrackPointAssert;
import de.dennisguse.opentracks.services.sensors.BluetoothRemoteSensorManager;
import de.dennisguse.opentracks.util.PreferencesUtils;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
@@ -114,16 +113,17 @@ public class TrackRecordingServiceTestLocation {
assertFalse(service.isRecording());
List<TrackPoint> trackPoints = TestDataUtil.getTrackPoints(contentProviderUtils, trackId);
assertEquals(8, trackPoints.size());
assertTrackPoints(List.of(
new Pair<>(TrackPoint.Type.SEGMENT_START_MANUAL, null),
new Pair<>(TrackPoint.Type.TRACKPOINT, 1),
new Pair<>(TrackPoint.Type.TRACKPOINT, 2),
new Pair<>(TrackPoint.Type.TRACKPOINT, 3),
new Pair<>(TrackPoint.Type.TRACKPOINT, 4),
new Pair<>(TrackPoint.Type.TRACKPOINT, 5),
new Pair<>(TrackPoint.Type.TRACKPOINT, 6),
new Pair<>(TrackPoint.Type.SEGMENT_END_MANUAL, null)
TrackPointAssert a = new TrackPointAssert()
.ignoreTime();
a.assertEquals(List.of(
a.expect(TrackPoint.Type.SEGMENT_START_MANUAL),
a.expect(TrackPoint.Type.TRACKPOINT, 1),
a.expect(TrackPoint.Type.TRACKPOINT, 2),
a.expect(TrackPoint.Type.TRACKPOINT, 3),
a.expect(TrackPoint.Type.TRACKPOINT, 4),
a.expect(TrackPoint.Type.TRACKPOINT, 5),
a.expect(TrackPoint.Type.TRACKPOINT, 6),
a.expect(TrackPoint.Type.SEGMENT_END_MANUAL)
), trackPoints);
}
@@ -148,33 +148,16 @@ public class TrackRecordingServiceTestLocation {
assertFalse(service.isRecording());
List<TrackPoint> trackPoints = TestDataUtil.getTrackPoints(contentProviderUtils, trackId);
assertEquals(4, trackPoints.size());
assertTrackPoints(List.of(
new Pair<>(TrackPoint.Type.SEGMENT_START_MANUAL, null),
new Pair<>(TrackPoint.Type.TRACKPOINT, 1),
new Pair<>(TrackPoint.Type.TRACKPOINT, 6),
new Pair<>(TrackPoint.Type.SEGMENT_END_MANUAL, null)
TrackPointAssert a = new TrackPointAssert()
.ignoreTime();
a.assertEquals(List.of(
a.expect(TrackPoint.Type.SEGMENT_START_MANUAL),
a.expect(TrackPoint.Type.TRACKPOINT, 1),
a.expect(TrackPoint.Type.TRACKPOINT, 6),
a.expect(TrackPoint.Type.SEGMENT_END_MANUAL)
), trackPoints);
}
// @MediumTest
// @Test
// public void testOnLocationChangedAsync_repeatedTime() throws Exception {
// // when
// TrackRecordingServiceTest.insertLocation(service, 45.0, 35.0, 5, 15, 5);
// TrackRecordingServiceTest.insertLocation(service, 55.0, 35.0, 5, 15, 5);
// TrackRecordingServiceTest.insertLocation(service, 65.0, 35.0, 5, 15, 5);
//
// service.endCurrentTrack();
//
// // then
// Assert.assertFalse(service.isRecording());
//
// List<TrackPoint> trackPoints = contentProviderUtils.getTrackPoints(trackId);
// Assert.assertEquals(1, trackPoints.size());
// Assert.assertEquals(45.0, trackPoints.get(0).getLatitude(), 0.01);
// }
@MediumTest
@Test
public void testOnLocationChangedAsync_idle() throws Exception {
@@ -195,12 +178,14 @@ public class TrackRecordingServiceTestLocation {
assertFalse(service.isRecording());
List<TrackPoint> trackPoints = TestDataUtil.getTrackPoints(contentProviderUtils, trackId);
assertTrackPoints(List.of(
new Pair<>(TrackPoint.Type.SEGMENT_START_MANUAL, null),
new Pair<>(TrackPoint.Type.TRACKPOINT, 1),
new Pair<>(TrackPoint.Type.TRACKPOINT, 2),
new Pair<>(TrackPoint.Type.TRACKPOINT, 6),
new Pair<>(TrackPoint.Type.SEGMENT_END_MANUAL, null)
TrackPointAssert a = new TrackPointAssert()
.ignoreTime();
a.assertEquals(List.of(
a.expect(TrackPoint.Type.SEGMENT_START_MANUAL),
a.expect(TrackPoint.Type.TRACKPOINT, 1),
a.expect(TrackPoint.Type.TRACKPOINT, 2),
a.expect(TrackPoint.Type.TRACKPOINT, 6),
a.expect(TrackPoint.Type.SEGMENT_END_MANUAL)
), trackPoints);
}
@@ -224,14 +209,15 @@ public class TrackRecordingServiceTestLocation {
assertFalse(service.isRecording());
List<TrackPoint> trackPoints = TestDataUtil.getTrackPoints(contentProviderUtils, trackId);
assertEquals(6, trackPoints.size());
assertTrackPoints(List.of(
new Pair<>(TrackPoint.Type.SEGMENT_START_MANUAL, null),
new Pair<>(TrackPoint.Type.TRACKPOINT, 1),
new Pair<>(TrackPoint.Type.TRACKPOINT, 2),
new Pair<>(TrackPoint.Type.TRACKPOINT, 5), //TODO Check why this trackPoint is inserted.
new Pair<>(TrackPoint.Type.TRACKPOINT, 6),
new Pair<>(TrackPoint.Type.SEGMENT_END_MANUAL, null)
TrackPointAssert a = new TrackPointAssert()
.ignoreTime();
a.assertEquals(List.of(
a.expect(TrackPoint.Type.SEGMENT_START_MANUAL),
a.expect(TrackPoint.Type.TRACKPOINT, 1),
a.expect(TrackPoint.Type.TRACKPOINT, 2),
a.expect(TrackPoint.Type.TRACKPOINT, 5), //TODO Check why this trackPoint is inserted.
a.expect(TrackPoint.Type.TRACKPOINT, 6),
a.expect(TrackPoint.Type.SEGMENT_END_MANUAL)
), trackPoints);
}
@@ -270,16 +256,17 @@ public class TrackRecordingServiceTestLocation {
assertFalse(service.isRecording());
List<TrackPoint> trackPoints = TestDataUtil.getTrackPoints(contentProviderUtils, trackId);
assertEquals(8, trackPoints.size());
assertTrackPoints(List.of(
new Pair<>(TrackPoint.Type.SEGMENT_START_MANUAL, null),
new Pair<>(TrackPoint.Type.TRACKPOINT, 1),
new Pair<>(TrackPoint.Type.TRACKPOINT, 2),
new Pair<>(TrackPoint.Type.TRACKPOINT, 3),
new Pair<>(TrackPoint.Type.TRACKPOINT, 4),
new Pair<>(TrackPoint.Type.TRACKPOINT, 5),
new Pair<>(TrackPoint.Type.TRACKPOINT, 6),
new Pair<>(TrackPoint.Type.SEGMENT_END_MANUAL, null)
TrackPointAssert a = new TrackPointAssert()
.ignoreTime();
a.assertEquals(List.of(
a.expect(TrackPoint.Type.SEGMENT_START_MANUAL),
a.expect(TrackPoint.Type.TRACKPOINT, 1, 5f),
a.expect(TrackPoint.Type.TRACKPOINT, 2, 5f),
a.expect(TrackPoint.Type.TRACKPOINT, 3, 5f),
a.expect(TrackPoint.Type.TRACKPOINT, 4, 5f),
a.expect(TrackPoint.Type.TRACKPOINT, 5, 5f),
a.expect(TrackPoint.Type.TRACKPOINT, 6, 5f),
a.expecHeartrate(TrackPoint.Type.SEGMENT_END_MANUAL, 5f)
), trackPoints);
}
@@ -302,27 +289,19 @@ public class TrackRecordingServiceTestLocation {
assertFalse(service.isRecording());
List<TrackPoint> trackPoints = TestDataUtil.getTrackPoints(contentProviderUtils, trackId);
assertEquals(7, trackPoints.size());
assertTrackPoints(List.of(
new Pair<>(TrackPoint.Type.SEGMENT_START_MANUAL, null),
new Pair<>(TrackPoint.Type.TRACKPOINT, 1),
new Pair<>(TrackPoint.Type.SEGMENT_START_AUTOMATIC, 2),
new Pair<>(TrackPoint.Type.TRACKPOINT, 3),
TrackPointAssert a = new TrackPointAssert()
.ignoreTime();
a.assertEquals(List.of(
a.expect(TrackPoint.Type.SEGMENT_START_MANUAL),
a.expect(TrackPoint.Type.TRACKPOINT, 1),
new Pair<>(TrackPoint.Type.SEGMENT_START_AUTOMATIC, 4),
new Pair<>(TrackPoint.Type.TRACKPOINT, 5),
new Pair<>(TrackPoint.Type.SEGMENT_END_MANUAL, null)
a.expect(TrackPoint.Type.SEGMENT_START_AUTOMATIC, 2),
a.expect(TrackPoint.Type.TRACKPOINT, 3),
a.expect(TrackPoint.Type.SEGMENT_START_AUTOMATIC, 4),
a.expect(TrackPoint.Type.TRACKPOINT, 5),
a.expect(TrackPoint.Type.SEGMENT_END_MANUAL)
), trackPoints);
}
private void assertTrackPoints(List<Pair<TrackPoint.Type, Object>> typeAndAccuracy, List<TrackPoint> actual) {
assertEquals(typeAndAccuracy.size(), actual.size());
for (int i = 0; i < typeAndAccuracy.size(); i++) {
assertEquals(typeAndAccuracy.get(i).first, actual.get(i).getType());
if (typeAndAccuracy.get(i).second != null) {
assertEquals((Integer) typeAndAccuracy.get(i).second, actual.get(i).getAccuracy(), 0.01);
}
}
}
}