diff --git a/src/androidTest/java/de/dennisguse/opentracks/io/file/importer/ExportImportTest.java b/src/androidTest/java/de/dennisguse/opentracks/io/file/importer/ExportImportTest.java index 944d8dc23..3bd201b06 100644 --- a/src/androidTest/java/de/dennisguse/opentracks/io/file/importer/ExportImportTest.java +++ b/src/androidTest/java/de/dennisguse/opentracks/io/file/importer/ExportImportTest.java @@ -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 trackPoints, boolean verifyPower, boolean verifyHeartrate, boolean verifyCadence, boolean verifyAltitudeGain, boolean verifyAltitudeLoss, boolean verifyDistance) { - List 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); diff --git a/src/androidTest/java/de/dennisguse/opentracks/io/file/importer/GPXImportTest.java b/src/androidTest/java/de/dennisguse/opentracks/io/file/importer/GPXImportTest.java index 7c75e6cab..95db90def 100644 --- a/src/androidTest/java/de/dennisguse/opentracks/io/file/importer/GPXImportTest.java +++ b/src/androidTest/java/de/dennisguse/opentracks/io/file/importer/GPXImportTest.java @@ -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); } } \ No newline at end of file diff --git a/src/androidTest/java/de/dennisguse/opentracks/io/file/importer/KMLImportTest.java b/src/androidTest/java/de/dennisguse/opentracks/io/file/importer/KMLImportTest.java index 084680c54..a06f92750 100644 --- a/src/androidTest/java/de/dennisguse/opentracks/io/file/importer/KMLImportTest.java +++ b/src/androidTest/java/de/dennisguse/opentracks/io/file/importer/KMLImportTest.java @@ -78,13 +78,14 @@ public class KMLImportTest { // 3. trackpoints List 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 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 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); } /** diff --git a/src/androidTest/java/de/dennisguse/opentracks/io/file/importer/TrackPointAssert.java b/src/androidTest/java/de/dennisguse/opentracks/io/file/importer/TrackPointAssert.java new file mode 100644 index 000000000..34b9c795e --- /dev/null +++ b/src/androidTest/java/de/dennisguse/opentracks/io/file/importer/TrackPointAssert.java @@ -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 expected, List 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; + } +} diff --git a/src/androidTest/java/de/dennisguse/opentracks/services/TrackRecordingServiceTestLocation.java b/src/androidTest/java/de/dennisguse/opentracks/services/TrackRecordingServiceTestLocation.java index d300cc38b..e145a96ab 100644 --- a/src/androidTest/java/de/dennisguse/opentracks/services/TrackRecordingServiceTestLocation.java +++ b/src/androidTest/java/de/dennisguse/opentracks/services/TrackRecordingServiceTestLocation.java @@ -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 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 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 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 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 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 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 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> typeAndAccuracy, List 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); - } - } - } } diff --git a/src/main/java/de/dennisguse/opentracks/content/data/TrackPoint.java b/src/main/java/de/dennisguse/opentracks/content/data/TrackPoint.java index 9c886486b..96b60c6e3 100644 --- a/src/main/java/de/dennisguse/opentracks/content/data/TrackPoint.java +++ b/src/main/java/de/dennisguse/opentracks/content/data/TrackPoint.java @@ -161,8 +161,9 @@ public class TrackPoint { return type; } - public void setType(@NonNull Type type) { + public TrackPoint setType(@NonNull Type type) { this.type = type; + return this; } public boolean isSegmentStart() { @@ -193,16 +194,18 @@ public class TrackPoint { return latitude; } - public void setLatitude(double latitude) { + public TrackPoint setLatitude(double latitude) { this.latitude = latitude; + return this; } public double getLongitude() { return longitude; } - public void setLongitude(double longitude) { + public TrackPoint setLongitude(double longitude) { this.longitude = longitude; + return this; } //TODO Better return null, if no location is present aka latitude == null etc. @@ -235,8 +238,9 @@ public class TrackPoint { return altitudeGain_m; } - public void setAltitudeGain(Float altitudeGain_m) { + public TrackPoint setAltitudeGain(Float altitudeGain_m) { this.altitudeGain_m = altitudeGain_m; + return this; } public boolean hasAltitudeLoss() { @@ -247,16 +251,18 @@ public class TrackPoint { return altitudeLoss_m; } - public void setAltitudeLoss(Float altitudeLoss_m) { + public TrackPoint setAltitudeLoss(Float altitudeLoss_m) { this.altitudeLoss_m = altitudeLoss_m; + return this; } public Instant getTime() { return time; } - public void setTime(Instant time) { + public TrackPoint setTime(Instant time) { this.time = time; + return this; } public boolean isRecent() { @@ -278,8 +284,9 @@ public class TrackPoint { this.altitude = Altitude.WGS84.of(altitude_m); } - public void setAltitude(Altitude altitude) { + public TrackPoint setAltitude(Altitude altitude) { this.altitude = altitude; + return this; } public boolean hasSpeed() { @@ -290,8 +297,9 @@ public class TrackPoint { return speed; } - public void setSpeed(Speed speed) { + public TrackPoint setSpeed(Speed speed) { this.speed = speed; + return this; } public boolean isMoving() { @@ -306,8 +314,9 @@ public class TrackPoint { return bearing; } - public void setBearing(Float bearing) { + public TrackPoint setBearing(Float bearing) { this.bearing = bearing; + return this; } public boolean hasAccuracy() { @@ -318,8 +327,9 @@ public class TrackPoint { return accuracy; } - public void setAccuracy(float horizontalAccuracy) { + public TrackPoint setAccuracy(float horizontalAccuracy) { this.accuracy = horizontalAccuracy; + return this; } @Nullable @@ -357,8 +367,9 @@ public class TrackPoint { return sensorDistance; } - public void setSensorDistance(Distance distance_m) { + public TrackPoint setSensorDistance(Distance distance_m) { this.sensorDistance = distance_m; + return this; } public boolean hasSensorData() { @@ -373,8 +384,9 @@ public class TrackPoint { return heartRate_bpm; } - public void setHeartRate_bpm(Float heartRate_bpm) { + public TrackPoint setHeartRate_bpm(Float heartRate_bpm) { this.heartRate_bpm = heartRate_bpm; + return this; } public boolean hasCyclingCadence() { @@ -385,8 +397,9 @@ public class TrackPoint { return cyclingCadence_rpm; } - public void setCyclingCadence_rpm(Float cyclingCadence_rpm) { + public TrackPoint setCyclingCadence_rpm(Float cyclingCadence_rpm) { this.cyclingCadence_rpm = cyclingCadence_rpm; + return this; } public boolean hasPower() { @@ -397,8 +410,9 @@ public class TrackPoint { return power; } - public void setPower(Float power) { + public TrackPoint setPower(Float power) { this.power = power; + return this; } @NonNull