Cleanup: rename waypoint to marker (tests).

This commit is contained in:
Dennis Guse
2020-12-13 17:52:03 +01:00
parent 55fa6d2d79
commit 2255624235
4 changed files with 161 additions and 292 deletions
@@ -87,19 +87,19 @@ public class TestDataUtil {
} }
/** /**
* Creates a Waypoint with a photo. * Creates a Marker with a photo.
* *
* @param context The context. * @param context The context.
* @param trackId The track id. * @param trackId The track id.
* @param location The location. * @param location The location.
* @return the Waypoint created. * @return the Marker created.
*/ */
public static Marker createWaypointWithPhoto(Context context, Track.Id trackId, Location location) throws IOException { public static Marker createMarkerWithPhoto(Context context, Track.Id trackId, Location location) throws IOException {
File dstFile = new File(FileUtils.getImageUrl(context, trackId)); File dstFile = new File(FileUtils.getImageUrl(context, trackId));
dstFile.createNewFile(); dstFile.createNewFile();
Uri photoUri = FileUtils.getUriForFile(context, dstFile); Uri photoUri = FileUtils.getUriForFile(context, dstFile);
String photoUrl = photoUri.toString(); String photoUrl = photoUri.toString();
return new Marker("Waypoint name", "Waypoint description", "Waypoint category", "", trackId, 0.0, 0, location, photoUrl); return new Marker("Marker name", "Marker description", "Marker category", "", trackId, 0.0, 0, location, photoUrl);
} }
} }
@@ -65,7 +65,7 @@ import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class) @RunWith(MockitoJUnitRunner.class)
public class CustomContentProviderUtilsTest { public class CustomContentProviderUtilsTest {
private static final String NAME_PREFIX = "test name"; private static final String NAME_PREFIX = "test name";
private static final String MOCK_DESC = "Mock Next Waypoint Desc!"; private static final String MOCK_DESC = "Mock Next Marker Desc!";
private static final String TEST_DESC = "Test Desc!"; private static final String TEST_DESC = "Test Desc!";
private static final String TEST_DESC_NEW = "Test Desc new!"; private static final String TEST_DESC_NEW = "Test Desc new!";
private static final String TEST_NAME_NEW = "Test Name new!"; private static final String TEST_NAME_NEW = "Test Name new!";
@@ -208,20 +208,20 @@ public class CustomContentProviderUtilsTest {
*/ */
@Test @Test
public void testDeleteAllTracks() { public void testDeleteAllTracks() {
// Insert track, points and waypoint at first. // Insert track, points and marker at first.
Track.Id trackId = new Track.Id(System.currentTimeMillis()); Track.Id trackId = new Track.Id(System.currentTimeMillis());
TestDataUtil.createTrackAndInsert(contentProviderUtils, trackId, 10); TestDataUtil.createTrackAndInsert(contentProviderUtils, trackId, 10);
Marker waypoint = new Marker(trackId, contentProviderUtils.getLastValidTrackPoint(trackId)); Marker marker = new Marker(trackId, contentProviderUtils.getLastValidTrackPoint(trackId));
contentProviderUtils.insertMarker(waypoint); contentProviderUtils.insertMarker(marker);
ContentResolver contentResolver = context.getContentResolver(); ContentResolver contentResolver = context.getContentResolver();
Cursor tracksCursor = contentResolver.query(TracksColumns.CONTENT_URI, null, null, null, TracksColumns._ID); Cursor tracksCursor = contentResolver.query(TracksColumns.CONTENT_URI, null, null, null, TracksColumns._ID);
assertEquals(1, tracksCursor.getCount()); assertEquals(1, tracksCursor.getCount());
Cursor tracksPointsCursor = contentResolver.query(TrackPointsColumns.CONTENT_URI_BY_ID, null, null, null, TrackPointsColumns._ID); Cursor tracksPointsCursor = contentResolver.query(TrackPointsColumns.CONTENT_URI_BY_ID, null, null, null, TrackPointsColumns._ID);
assertEquals(10, tracksPointsCursor.getCount()); assertEquals(10, tracksPointsCursor.getCount());
Cursor waypointCursor = contentResolver.query(MarkerColumns.CONTENT_URI, null, null, null, MarkerColumns._ID); Cursor markerCursor = contentResolver.query(MarkerColumns.CONTENT_URI, null, null, null, MarkerColumns._ID);
assertEquals(1, waypointCursor.getCount()); assertEquals(1, markerCursor.getCount());
// Delete all. // Delete all.
contentProviderUtils.deleteAllTracks(context); contentProviderUtils.deleteAllTracks(context);
// Check whether all have been deleted. // Check whether all have been deleted.
@@ -229,32 +229,32 @@ public class CustomContentProviderUtilsTest {
assertEquals(0, tracksCursor.getCount()); assertEquals(0, tracksCursor.getCount());
tracksPointsCursor = contentResolver.query(TrackPointsColumns.CONTENT_URI_BY_ID, null, null, null, TrackPointsColumns._ID); tracksPointsCursor = contentResolver.query(TrackPointsColumns.CONTENT_URI_BY_ID, null, null, null, TrackPointsColumns._ID);
assertEquals(0, tracksPointsCursor.getCount()); assertEquals(0, tracksPointsCursor.getCount());
waypointCursor = contentResolver.query(MarkerColumns.CONTENT_URI, null, null, null, MarkerColumns._ID); markerCursor = contentResolver.query(MarkerColumns.CONTENT_URI, null, null, null, MarkerColumns._ID);
assertEquals(0, waypointCursor.getCount()); assertEquals(0, markerCursor.getCount());
} }
/** /**
* Tests the method {@link ContentProviderUtils#deleteAllTracks(Context)} * Tests the method {@link ContentProviderUtils#deleteAllTracks(Context)}
*/ */
@Test @Test
public void testDeleteAllTracks_withWaypointAndPhoto() throws IOException { public void testDeleteAllTracks_withMarkerAndPhoto() throws IOException {
// Insert track, points and waypoint with photo at first. // Insert track, points and marker with photo at first.
Track.Id trackId = new Track.Id(System.currentTimeMillis()); Track.Id trackId = new Track.Id(System.currentTimeMillis());
Track track = TestDataUtil.createTrackAndInsert(contentProviderUtils, trackId, 10); Track track = TestDataUtil.createTrackAndInsert(contentProviderUtils, trackId, 10);
TrackPoint trackPoint = contentProviderUtils.getLastValidTrackPoint(trackId); TrackPoint trackPoint = contentProviderUtils.getLastValidTrackPoint(trackId);
Marker waypoint = TestDataUtil.createWaypointWithPhoto(context, trackId, trackPoint.getLocation()); Marker marker = TestDataUtil.createMarkerWithPhoto(context, trackId, trackPoint.getLocation());
contentProviderUtils.insertMarker(waypoint); contentProviderUtils.insertMarker(marker);
ContentResolver contentResolver = context.getContentResolver(); ContentResolver contentResolver = context.getContentResolver();
Cursor tracksCursor = contentResolver.query(TracksColumns.CONTENT_URI, null, null, null, TracksColumns._ID); Cursor tracksCursor = contentResolver.query(TracksColumns.CONTENT_URI, null, null, null, TracksColumns._ID);
assertEquals(1, tracksCursor.getCount()); assertEquals(1, tracksCursor.getCount());
Cursor tracksPointsCursor = contentResolver.query(TrackPointsColumns.CONTENT_URI_BY_ID, null, null, null, TrackPointsColumns._ID); Cursor tracksPointsCursor = contentResolver.query(TrackPointsColumns.CONTENT_URI_BY_ID, null, null, null, TrackPointsColumns._ID);
assertEquals(10, tracksPointsCursor.getCount()); assertEquals(10, tracksPointsCursor.getCount());
Cursor waypointCursor = contentResolver.query(MarkerColumns.CONTENT_URI, null, null, null, MarkerColumns._ID); Cursor markerCursor = contentResolver.query(MarkerColumns.CONTENT_URI, null, null, null, MarkerColumns._ID);
assertEquals(1, waypointCursor.getCount()); assertEquals(1, markerCursor.getCount());
// Check waypoint has photo and it's in the external storage. // Check marker has photo and it's in the external storage.
assertTrue(waypoint.hasPhoto()); assertTrue(marker.hasPhoto());
File dir = FileUtils.getPhotoDir(context, trackId); File dir = FileUtils.getPhotoDir(context, trackId);
assertTrue(dir.isDirectory()); assertTrue(dir.isDirectory());
assertEquals(1, dir.list().length); assertEquals(1, dir.list().length);
@@ -266,8 +266,8 @@ public class CustomContentProviderUtilsTest {
assertEquals(0, tracksCursor.getCount()); assertEquals(0, tracksCursor.getCount());
tracksPointsCursor = contentResolver.query(TrackPointsColumns.CONTENT_URI_BY_ID, null, null, null, TrackPointsColumns._ID); tracksPointsCursor = contentResolver.query(TrackPointsColumns.CONTENT_URI_BY_ID, null, null, null, TrackPointsColumns._ID);
assertEquals(0, tracksPointsCursor.getCount()); assertEquals(0, tracksPointsCursor.getCount());
waypointCursor = contentResolver.query(MarkerColumns.CONTENT_URI, null, null, null, MarkerColumns._ID); markerCursor = contentResolver.query(MarkerColumns.CONTENT_URI, null, null, null, MarkerColumns._ID);
assertEquals(0, waypointCursor.getCount()); assertEquals(0, markerCursor.getCount());
assertFalse(dir.exists()); assertFalse(dir.exists());
} }
@@ -287,16 +287,16 @@ public class CustomContentProviderUtilsTest {
TestDataUtil.createTrackAndInsert(contentProviderUtils, trackId2, 10); TestDataUtil.createTrackAndInsert(contentProviderUtils, trackId2, 10);
TestDataUtil.createTrackAndInsert(contentProviderUtils, trackId3, 10); TestDataUtil.createTrackAndInsert(contentProviderUtils, trackId3, 10);
Marker waypoint = new Marker(trackId1, contentProviderUtils.getLastValidTrackPoint(trackId2)); Marker marker = new Marker(trackId1, contentProviderUtils.getLastValidTrackPoint(trackId2));
contentProviderUtils.insertMarker(waypoint); contentProviderUtils.insertMarker(marker);
ContentResolver contentResolver = context.getContentResolver(); ContentResolver contentResolver = context.getContentResolver();
Cursor tracksCursor = contentResolver.query(TracksColumns.CONTENT_URI, null, null, null, TracksColumns._ID); Cursor tracksCursor = contentResolver.query(TracksColumns.CONTENT_URI, null, null, null, TracksColumns._ID);
assertEquals(3, tracksCursor.getCount()); assertEquals(3, tracksCursor.getCount());
Cursor tracksPointsCursor = contentResolver.query(TrackPointsColumns.CONTENT_URI_BY_ID, null, null, null, TrackPointsColumns._ID); Cursor tracksPointsCursor = contentResolver.query(TrackPointsColumns.CONTENT_URI_BY_ID, null, null, null, TrackPointsColumns._ID);
assertEquals(20, tracksPointsCursor.getCount()); assertEquals(20, tracksPointsCursor.getCount());
Cursor waypointCursor = contentResolver.query(MarkerColumns.CONTENT_URI, null, null, null, MarkerColumns._ID); Cursor markerCursor = contentResolver.query(MarkerColumns.CONTENT_URI, null, null, null, MarkerColumns._ID);
assertEquals(1, waypointCursor.getCount()); assertEquals(1, markerCursor.getCount());
// Delete one track. // Delete one track.
contentProviderUtils.deleteTrack(context, trackId1); contentProviderUtils.deleteTrack(context, trackId1);
// Check whether all data of a track has been deleted. // Check whether all data of a track has been deleted.
@@ -304,15 +304,15 @@ public class CustomContentProviderUtilsTest {
assertEquals(2, tracksCursor.getCount()); assertEquals(2, tracksCursor.getCount());
tracksPointsCursor = contentResolver.query(TrackPointsColumns.CONTENT_URI_BY_ID, null, null, null, TrackPointsColumns._ID); tracksPointsCursor = contentResolver.query(TrackPointsColumns.CONTENT_URI_BY_ID, null, null, null, TrackPointsColumns._ID);
assertEquals(20, tracksPointsCursor.getCount()); assertEquals(20, tracksPointsCursor.getCount());
waypointCursor = contentResolver.query(MarkerColumns.CONTENT_URI, null, null, null, MarkerColumns._ID); markerCursor = contentResolver.query(MarkerColumns.CONTENT_URI, null, null, null, MarkerColumns._ID);
assertEquals(0, waypointCursor.getCount()); assertEquals(0, markerCursor.getCount());
} }
/** /**
* Tests the method {@link ContentProviderUtils#deleteTrack(Context, Track.Id)}. * Tests the method {@link ContentProviderUtils#deleteTrack(Context, Track.Id)}.
*/ */
@Test @Test
public void testDeleteTrack_withWaypointPhoto() throws IOException { public void testDeleteTrack_withMarkerPhoto() throws IOException {
// Insert three tracks. // Insert three tracks.
long random = System.currentTimeMillis(); long random = System.currentTimeMillis();
Track.Id trackId1 = new Track.Id(random); Track.Id trackId1 = new Track.Id(random);
@@ -323,15 +323,15 @@ public class CustomContentProviderUtilsTest {
TestDataUtil.createTrackAndInsert(contentProviderUtils, trackId2, 10); TestDataUtil.createTrackAndInsert(contentProviderUtils, trackId2, 10);
TestDataUtil.createTrackAndInsert(contentProviderUtils, trackId3, 10); TestDataUtil.createTrackAndInsert(contentProviderUtils, trackId3, 10);
// Insert a waypoint in tracks trackId and trackId + 1. // Insert a marker in tracks trackId and trackId + 1.
TrackPoint trackPoint1 = contentProviderUtils.getLastValidTrackPoint(trackId1); TrackPoint trackPoint1 = contentProviderUtils.getLastValidTrackPoint(trackId1);
Marker waypoint1 = TestDataUtil.createWaypointWithPhoto(context, trackId1, trackPoint1.getLocation()); Marker marker1 = TestDataUtil.createMarkerWithPhoto(context, trackId1, trackPoint1.getLocation());
contentProviderUtils.insertMarker(waypoint1); contentProviderUtils.insertMarker(marker1);
File dir1 = FileUtils.getPhotoDir(context, trackId1); File dir1 = FileUtils.getPhotoDir(context, trackId1);
TrackPoint trackPoint2 = contentProviderUtils.getLastValidTrackPoint(trackId2); TrackPoint trackPoint2 = contentProviderUtils.getLastValidTrackPoint(trackId2);
Marker waypoint2 = TestDataUtil.createWaypointWithPhoto(context, trackId2, trackPoint2.getLocation()); Marker marker2 = TestDataUtil.createMarkerWithPhoto(context, trackId2, trackPoint2.getLocation());
contentProviderUtils.insertMarker(waypoint2); contentProviderUtils.insertMarker(marker2);
File dir2 = FileUtils.getPhotoDir(context, trackId2); File dir2 = FileUtils.getPhotoDir(context, trackId2);
// Check. // Check.
@@ -340,9 +340,9 @@ public class CustomContentProviderUtilsTest {
assertEquals(3, tracksCursor.getCount()); assertEquals(3, tracksCursor.getCount());
Cursor tracksPointsCursor = contentResolver.query(TrackPointsColumns.CONTENT_URI_BY_ID, null, null, null, TrackPointsColumns._ID); Cursor tracksPointsCursor = contentResolver.query(TrackPointsColumns.CONTENT_URI_BY_ID, null, null, null, TrackPointsColumns._ID);
assertEquals(30, tracksPointsCursor.getCount()); assertEquals(30, tracksPointsCursor.getCount());
Cursor waypointCursor = contentResolver.query(MarkerColumns.CONTENT_URI, null, null, null, MarkerColumns._ID); Cursor markerCursor = contentResolver.query(MarkerColumns.CONTENT_URI, null, null, null, MarkerColumns._ID);
assertEquals(2, waypointCursor.getCount()); assertEquals(2, markerCursor.getCount());
assertTrue(waypoint1.hasPhoto()); assertTrue(marker1.hasPhoto());
assertTrue(dir1.isDirectory()); assertTrue(dir1.isDirectory());
assertEquals(1, dir1.list().length); assertEquals(1, dir1.list().length);
assertTrue(dir1.exists()); assertTrue(dir1.exists());
@@ -356,8 +356,8 @@ public class CustomContentProviderUtilsTest {
assertEquals(2, tracksCursor.getCount()); assertEquals(2, tracksCursor.getCount());
tracksPointsCursor = contentResolver.query(TrackPointsColumns.CONTENT_URI_BY_ID, null, null, null, TrackPointsColumns._ID); tracksPointsCursor = contentResolver.query(TrackPointsColumns.CONTENT_URI_BY_ID, null, null, null, TrackPointsColumns._ID);
assertEquals(20, tracksPointsCursor.getCount()); assertEquals(20, tracksPointsCursor.getCount());
waypointCursor = contentResolver.query(MarkerColumns.CONTENT_URI, null, null, null, MarkerColumns._ID); markerCursor = contentResolver.query(MarkerColumns.CONTENT_URI, null, null, null, MarkerColumns._ID);
assertEquals(1, waypointCursor.getCount()); assertEquals(1, markerCursor.getCount());
assertFalse(dir1.exists()); assertFalse(dir1.exists());
assertTrue(dir2.exists()); assertTrue(dir2.exists());
} }
@@ -431,7 +431,7 @@ public class CustomContentProviderUtilsTest {
* Tests the method {@link ContentProviderUtils#createContentValues(Marker)}. * Tests the method {@link ContentProviderUtils#createContentValues(Marker)}.
*/ */
@Test @Test
public void testCreateContentValues_waypoint() { public void testCreateContentValues_marker() {
Track.Id trackId = new Track.Id(System.currentTimeMillis()); Track.Id trackId = new Track.Id(System.currentTimeMillis());
Pair<Track, TrackPoint[]> track = TestDataUtil.createTrack(trackId, 10); Pair<Track, TrackPoint[]> track = TestDataUtil.createTrack(trackId, 10);
@@ -452,16 +452,16 @@ public class CustomContentProviderUtilsTest {
track.first.setTrackStatistics(statistics); track.first.setTrackStatistics(statistics);
contentProviderUtils.insertTrack(track.first); contentProviderUtils.insertTrack(track.first);
Marker waypoint = new Marker(trackId, track.second[0]); Marker marker = new Marker(trackId, track.second[0]);
waypoint.setDescription(TEST_DESC); marker.setDescription(TEST_DESC);
contentProviderUtils.insertMarker(waypoint); contentProviderUtils.insertMarker(marker);
ContentProviderUtils contentProviderUtils = new ContentProviderUtils(contentResolverMock); ContentProviderUtils contentProviderUtils = new ContentProviderUtils(contentResolverMock);
Marker.Id waypointId = new Marker.Id(System.currentTimeMillis()); Marker.Id markerId = new Marker.Id(System.currentTimeMillis());
waypoint.setId(waypointId); marker.setId(markerId);
ContentValues contentValues = contentProviderUtils.createContentValues(waypoint); ContentValues contentValues = contentProviderUtils.createContentValues(marker);
assertEquals(waypointId.getId(), contentValues.get(MarkerColumns._ID)); assertEquals(markerId.getId(), contentValues.get(MarkerColumns._ID));
assertEquals((int) (TestDataUtil.INITIAL_LONGITUDE * 1000000), contentValues.get(MarkerColumns.LONGITUDE)); assertEquals((int) (TestDataUtil.INITIAL_LONGITUDE * 1000000), contentValues.get(MarkerColumns.LONGITUDE));
assertEquals(TEST_DESC, contentValues.get(MarkerColumns.DESCRIPTION)); assertEquals(TEST_DESC, contentValues.get(MarkerColumns.DESCRIPTION));
} }
@@ -470,7 +470,7 @@ public class CustomContentProviderUtilsTest {
* Tests the method {@link ContentProviderUtils#createMarker(Cursor)}. * Tests the method {@link ContentProviderUtils#createMarker(Cursor)}.
*/ */
@Test @Test
public void testCreateWaypoint() { public void testCreateMarker() {
int startColumnIndex = 1; int startColumnIndex = 1;
int columnIndex = startColumnIndex; int columnIndex = startColumnIndex;
when(cursorMock.getColumnIndexOrThrow(MarkerColumns._ID)).thenReturn(columnIndex++); when(cursorMock.getColumnIndexOrThrow(MarkerColumns._ID)).thenReturn(columnIndex++);
@@ -494,80 +494,80 @@ public class CustomContentProviderUtilsTest {
long trackId = 11L; long trackId = 11L;
when(cursorMock.getLong(columnIndex++)).thenReturn(trackId); when(cursorMock.getLong(columnIndex++)).thenReturn(trackId);
Marker waypoint = contentProviderUtils.createMarker(cursorMock); Marker marker = contentProviderUtils.createMarker(cursorMock);
assertEquals(id, waypoint.getId().getId()); assertEquals(id, marker.getId().getId());
assertEquals(name, waypoint.getName()); assertEquals(name, marker.getName());
assertEquals(trackId, waypoint.getTrackId().getId()); assertEquals(trackId, marker.getTrackId().getId());
} }
/** /**
* Tests the method * Tests the method
* {@link ContentProviderUtils#deleteMarker(Context, Marker.Id)} * {@link ContentProviderUtils#deleteMarker(Context, Marker.Id)}
* when there is only one waypoint in the track. * when there is only one marker in the track.
*/ */
@Test @Test
public void testDeleteWaypoint_onlyOneWayPoint() { public void testDeleteMarker_onlyOneMarker() {
Track.Id trackId = new Track.Id(System.currentTimeMillis()); Track.Id trackId = new Track.Id(System.currentTimeMillis());
TestDataUtil.createTrackAndInsert(contentProviderUtils, trackId, 10); TestDataUtil.createTrackAndInsert(contentProviderUtils, trackId, 10);
// Insert at first. // Insert at first.
Marker waypoint1 = new Marker(trackId, contentProviderUtils.getLastValidTrackPoint(trackId)); Marker marker1 = new Marker(trackId, contentProviderUtils.getLastValidTrackPoint(trackId));
waypoint1.setDescription(TEST_DESC); marker1.setDescription(TEST_DESC);
contentProviderUtils.insertMarker(waypoint1); contentProviderUtils.insertMarker(marker1);
// Check insert was done. // Check insert was done.
assertEquals(contentProviderUtils.getMarkerCount(trackId), 1); assertEquals(contentProviderUtils.getMarkerCount(trackId), 1);
// Get waypoint id that needs to delete. // Get marker id that needs to delete.
Marker.Id waypoint1Id = new Marker.Id(ContentUris.parseId(contentProviderUtils.insertMarker(waypoint1))); Marker.Id marker1Id = new Marker.Id(ContentUris.parseId(contentProviderUtils.insertMarker(marker1)));
// Delete // Delete
contentProviderUtils.deleteMarker(context, waypoint1Id); contentProviderUtils.deleteMarker(context, marker1Id);
assertNull(contentProviderUtils.getMarker(waypoint1Id)); assertNull(contentProviderUtils.getMarker(marker1Id));
} }
/** /**
* Tests the method * Tests the method
* {@link ContentProviderUtils#deleteMarker(Context, Marker.Id)} * {@link ContentProviderUtils#deleteMarker(Context, Marker.Id)}
* when there is only one waypoint in the track. * when there is only one marker in the track.
*/ */
@Test @Test
public void testDeleteWaypoint_onlyOneWayPointWithPhotoUrl() throws IOException { public void testDeleteMarker_onlyOneMarkerWithPhotoUrl() throws IOException {
Track.Id trackId = new Track.Id(System.currentTimeMillis()); Track.Id trackId = new Track.Id(System.currentTimeMillis());
TestDataUtil.createTrackAndInsert(contentProviderUtils, trackId, 10); TestDataUtil.createTrackAndInsert(contentProviderUtils, trackId, 10);
// Insert at first. // Insert at first.
TrackPoint trackPoint = contentProviderUtils.getLastValidTrackPoint(trackId); TrackPoint trackPoint = contentProviderUtils.getLastValidTrackPoint(trackId);
Marker waypoint1 = TestDataUtil.createWaypointWithPhoto(context, trackId, trackPoint.getLocation()); Marker marker1 = TestDataUtil.createMarkerWithPhoto(context, trackId, trackPoint.getLocation());
contentProviderUtils.insertMarker(waypoint1); contentProviderUtils.insertMarker(marker1);
// Check insert was done. // Check insert was done.
assertEquals(contentProviderUtils.getMarkerCount(trackId), 1); assertEquals(contentProviderUtils.getMarkerCount(trackId), 1);
// Get waypoint id that needs to delete. // Get marker id that needs to delete.
Marker.Id waypoint1Id = new Marker.Id(ContentUris.parseId(contentProviderUtils.insertMarker(waypoint1))); Marker.Id marker1Id = new Marker.Id(ContentUris.parseId(contentProviderUtils.insertMarker(marker1)));
// Check waypoint has photo and it's in the external storage. // Check marker has photo and it's in the external storage.
assertTrue(waypoint1.hasPhoto()); assertTrue(marker1.hasPhoto());
File dir = FileUtils.getPhotoDir(context, trackId); File dir = FileUtils.getPhotoDir(context, trackId);
assertTrue(dir.isDirectory()); assertTrue(dir.isDirectory());
assertEquals(1, dir.list().length); assertEquals(1, dir.list().length);
assertTrue(dir.exists()); assertTrue(dir.exists());
// Delete // Delete
contentProviderUtils.deleteMarker(context, waypoint1Id); contentProviderUtils.deleteMarker(context, marker1Id);
// Check waypoint doesn't exists and photo folder was deleted. // Check marker doesn't exists and photo folder was deleted.
assertNull(contentProviderUtils.getMarker(waypoint1Id)); assertNull(contentProviderUtils.getMarker(marker1Id));
assertFalse(dir.exists()); assertFalse(dir.exists());
} }
/** /**
* Tests the method {@link ContentProviderUtils#deleteMarker(Context, Marker.Id)} when there is more than one waypoint in the track. * Tests the method {@link ContentProviderUtils#deleteMarker(Context, Marker.Id)} when there is more than one marker in the track.
*/ */
@Test @Test
public void testDeleteWaypoint_hasNextWayPoint() { public void testDeleteMarker_hasNextMarker() {
Track.Id trackId = new Track.Id(System.currentTimeMillis()); Track.Id trackId = new Track.Id(System.currentTimeMillis());
TestDataUtil.createTrackAndInsert(contentProviderUtils, trackId, 10); TestDataUtil.createTrackAndInsert(contentProviderUtils, trackId, 10);
@@ -588,38 +588,38 @@ public class CustomContentProviderUtilsTest {
// TestDataUtil.insertTrackWithLocations(contentProviderUtils, track); // TestDataUtil.insertTrackWithLocations(contentProviderUtils, track);
// Insert at first. // Insert at first.
Marker waypoint1 = new Marker(trackId, contentProviderUtils.getLastValidTrackPoint(trackId)); Marker marker1 = new Marker(trackId, contentProviderUtils.getLastValidTrackPoint(trackId));
waypoint1.setDescription(MOCK_DESC); marker1.setDescription(MOCK_DESC);
Marker.Id waypoint1Id = new Marker.Id(ContentUris.parseId(contentProviderUtils.insertMarker(waypoint1))); Marker.Id marker1Id = new Marker.Id(ContentUris.parseId(contentProviderUtils.insertMarker(marker1)));
Marker waypoint2 = new Marker(trackId, contentProviderUtils.getLastValidTrackPoint(trackId)); Marker marker2 = new Marker(trackId, contentProviderUtils.getLastValidTrackPoint(trackId));
waypoint2.setDescription(MOCK_DESC); marker2.setDescription(MOCK_DESC);
Marker.Id waypoint2Id = new Marker.Id(ContentUris.parseId(contentProviderUtils.insertMarker(waypoint2))); Marker.Id marker2Id = new Marker.Id(ContentUris.parseId(contentProviderUtils.insertMarker(marker2)));
// Delete // Delete
assertNotNull(contentProviderUtils.getMarker(waypoint1Id)); assertNotNull(contentProviderUtils.getMarker(marker1Id));
contentProviderUtils.deleteMarker(context, waypoint1Id); contentProviderUtils.deleteMarker(context, marker1Id);
assertNull(contentProviderUtils.getMarker(waypoint1Id)); assertNull(contentProviderUtils.getMarker(marker1Id));
assertEquals(MOCK_DESC, contentProviderUtils.getMarker(waypoint2Id).getDescription()); assertEquals(MOCK_DESC, contentProviderUtils.getMarker(marker2Id).getDescription());
} }
/** /**
* Tests the method {@link ContentProviderUtils#getNextMarkerNumber(Track.Id)}. * Tests the method {@link ContentProviderUtils#getNextMarkerNumber(Track.Id)}.
*/ */
@Test @Test
public void testGetNextWaypointNumber() { public void testGetNextMarkerNumber() {
Track.Id trackId = new Track.Id(System.currentTimeMillis()); Track.Id trackId = new Track.Id(System.currentTimeMillis());
TestDataUtil.createTrackAndInsert(contentProviderUtils, trackId, 10); TestDataUtil.createTrackAndInsert(contentProviderUtils, trackId, 10);
Marker waypoint1 = new Marker(trackId, contentProviderUtils.getLastValidTrackPoint(trackId)); Marker marker1 = new Marker(trackId, contentProviderUtils.getLastValidTrackPoint(trackId));
Marker waypoint2 = new Marker(trackId, contentProviderUtils.getLastValidTrackPoint(trackId)); Marker marker2 = new Marker(trackId, contentProviderUtils.getLastValidTrackPoint(trackId));
Marker waypoint3 = new Marker(trackId, contentProviderUtils.getLastValidTrackPoint(trackId)); Marker marker3 = new Marker(trackId, contentProviderUtils.getLastValidTrackPoint(trackId));
Marker waypoint4 = new Marker(trackId, contentProviderUtils.getLastValidTrackPoint(trackId)); Marker marker4 = new Marker(trackId, contentProviderUtils.getLastValidTrackPoint(trackId));
contentProviderUtils.insertMarker(waypoint1); contentProviderUtils.insertMarker(marker1);
contentProviderUtils.insertMarker(waypoint2); contentProviderUtils.insertMarker(marker2);
contentProviderUtils.insertMarker(waypoint3); contentProviderUtils.insertMarker(marker3);
contentProviderUtils.insertMarker(waypoint4); contentProviderUtils.insertMarker(marker4);
assertEquals(4, contentProviderUtils.getNextMarkerNumber(trackId)); assertEquals(4, contentProviderUtils.getNextMarkerNumber(trackId));
} }
@@ -629,53 +629,53 @@ public class CustomContentProviderUtilsTest {
* {@link ContentProviderUtils#getMarker(Marker.Id)}. * {@link ContentProviderUtils#getMarker(Marker.Id)}.
*/ */
@Test @Test
public void testInsertAndGetWaypoint() { public void testInsertAndGetMarker() {
Track.Id trackId = new Track.Id(System.currentTimeMillis()); Track.Id trackId = new Track.Id(System.currentTimeMillis());
TestDataUtil.createTrackAndInsert(contentProviderUtils, trackId, 10); TestDataUtil.createTrackAndInsert(contentProviderUtils, trackId, 10);
Marker waypoint = new Marker(trackId, contentProviderUtils.getLastValidTrackPoint(trackId)); Marker marker = new Marker(trackId, contentProviderUtils.getLastValidTrackPoint(trackId));
waypoint.setDescription(TEST_DESC); marker.setDescription(TEST_DESC);
Marker.Id waypointId = new Marker.Id(ContentUris.parseId(contentProviderUtils.insertMarker(waypoint))); Marker.Id markerId = new Marker.Id(ContentUris.parseId(contentProviderUtils.insertMarker(marker)));
assertEquals(TEST_DESC, contentProviderUtils.getMarker(waypointId).getDescription()); assertEquals(TEST_DESC, contentProviderUtils.getMarker(markerId).getDescription());
} }
/** /**
* Tests the method {@link ContentProviderUtils#updateMarker(Context, Marker)}. * Tests the method {@link ContentProviderUtils#updateMarker(Context, Marker)}.
*/ */
@Test @Test
public void testUpdateWaypoint() { public void testUpdateMarker() {
Track.Id trackId = new Track.Id(System.currentTimeMillis()); Track.Id trackId = new Track.Id(System.currentTimeMillis());
TestDataUtil.createTrackAndInsert(contentProviderUtils, trackId, 10); TestDataUtil.createTrackAndInsert(contentProviderUtils, trackId, 10);
// Insert at first. // Insert at first.
Marker waypoint = new Marker(trackId, contentProviderUtils.getLastValidTrackPoint(trackId)); Marker marker = new Marker(trackId, contentProviderUtils.getLastValidTrackPoint(trackId));
waypoint.setDescription(TEST_DESC); marker.setDescription(TEST_DESC);
Marker.Id waypointId = new Marker.Id(ContentUris.parseId(contentProviderUtils.insertMarker(waypoint))); Marker.Id markerId = new Marker.Id(ContentUris.parseId(contentProviderUtils.insertMarker(marker)));
// Update // Update
waypoint = contentProviderUtils.getMarker(waypointId); marker = contentProviderUtils.getMarker(markerId);
waypoint.setDescription(TEST_DESC_NEW); marker.setDescription(TEST_DESC_NEW);
contentProviderUtils.updateMarker(context, waypoint); contentProviderUtils.updateMarker(context, marker);
assertEquals(TEST_DESC_NEW, contentProviderUtils.getMarker(waypointId).getDescription()); assertEquals(TEST_DESC_NEW, contentProviderUtils.getMarker(markerId).getDescription());
} }
/** /**
* Tests the method {@link ContentProviderUtils#updateMarker(Context, Marker)}. * Tests the method {@link ContentProviderUtils#updateMarker(Context, Marker)}.
*/ */
@Test @Test
public void testUpdateWaypoint_withPhoto() throws IOException { public void testUpdateMarker_withPhoto() throws IOException {
// tests after update waypoint with photo the photo remains in the storage. // tests after update marker with photo the photo remains in the storage.
Track.Id trackId = new Track.Id(System.currentTimeMillis()); Track.Id trackId = new Track.Id(System.currentTimeMillis());
TestDataUtil.createTrackAndInsert(contentProviderUtils, trackId, 10); TestDataUtil.createTrackAndInsert(contentProviderUtils, trackId, 10);
// Insert at first. // Insert at first.
TrackPoint trackPoint = contentProviderUtils.getLastValidTrackPoint(trackId); TrackPoint trackPoint = contentProviderUtils.getLastValidTrackPoint(trackId);
Marker waypoint = TestDataUtil.createWaypointWithPhoto(context, trackId, trackPoint.getLocation()); Marker marker = TestDataUtil.createMarkerWithPhoto(context, trackId, trackPoint.getLocation());
waypoint.setDescription(TEST_DESC); marker.setDescription(TEST_DESC);
Marker.Id waypointId = new Marker.Id(ContentUris.parseId(contentProviderUtils.insertMarker(waypoint))); Marker.Id markerId = new Marker.Id(ContentUris.parseId(contentProviderUtils.insertMarker(marker)));
File dir = new File(FileUtils.getPhotoDir(context), "" + trackId.getId()); File dir = new File(FileUtils.getPhotoDir(context), "" + trackId.getId());
assertTrue(dir.exists()); assertTrue(dir.exists());
@@ -683,14 +683,14 @@ public class CustomContentProviderUtilsTest {
assertEquals(1, dir.list().length); assertEquals(1, dir.list().length);
// Update // Update
waypoint = contentProviderUtils.getMarker(waypointId); marker = contentProviderUtils.getMarker(markerId);
waypoint.setName(TEST_NAME_NEW); marker.setName(TEST_NAME_NEW);
waypoint.setDescription(TEST_DESC_NEW); marker.setDescription(TEST_DESC_NEW);
contentProviderUtils.updateMarker(context, waypoint); contentProviderUtils.updateMarker(context, marker);
assertEquals(TEST_NAME_NEW, contentProviderUtils.getMarker(waypointId).getName()); assertEquals(TEST_NAME_NEW, contentProviderUtils.getMarker(markerId).getName());
assertEquals(TEST_DESC_NEW, contentProviderUtils.getMarker(waypointId).getDescription()); assertEquals(TEST_DESC_NEW, contentProviderUtils.getMarker(markerId).getDescription());
assertTrue(waypoint.hasPhoto()); assertTrue(marker.hasPhoto());
assertTrue(dir.exists()); assertTrue(dir.exists());
assertTrue(dir.isDirectory()); assertTrue(dir.isDirectory());
assertEquals(1, dir.list().length); assertEquals(1, dir.list().length);
@@ -700,17 +700,17 @@ public class CustomContentProviderUtilsTest {
* Tests the method {@link ContentProviderUtils#updateMarker(Context, Marker)}. * Tests the method {@link ContentProviderUtils#updateMarker(Context, Marker)}.
*/ */
@Test @Test
public void testUpdateWaypoint_delPhotoAndDir() throws IOException { public void testUpdateMarker_delPhotoAndDir() throws IOException {
// tests after update waypoint if user deletes the photo then file photo is deleted from the storage. Also empty directory is deleted. // tests after update marker if user deletes the photo then file photo is deleted from the storage. Also empty directory is deleted.
Track.Id trackId = new Track.Id(System.currentTimeMillis()); Track.Id trackId = new Track.Id(System.currentTimeMillis());
TestDataUtil.createTrackAndInsert(contentProviderUtils, trackId, 10); TestDataUtil.createTrackAndInsert(contentProviderUtils, trackId, 10);
// Insert at first. // Insert at first.
TrackPoint trackPoint = contentProviderUtils.getLastValidTrackPoint(trackId); TrackPoint trackPoint = contentProviderUtils.getLastValidTrackPoint(trackId);
Marker waypoint = TestDataUtil.createWaypointWithPhoto(context, trackId, trackPoint.getLocation()); Marker marker = TestDataUtil.createMarkerWithPhoto(context, trackId, trackPoint.getLocation());
waypoint.setDescription(TEST_DESC); marker.setDescription(TEST_DESC);
Marker.Id waypointId = new Marker.Id(ContentUris.parseId(contentProviderUtils.insertMarker(waypoint))); Marker.Id markerId = new Marker.Id(ContentUris.parseId(contentProviderUtils.insertMarker(marker)));
File dir = new File(FileUtils.getPhotoDir(context), "" + trackId.getId()); File dir = new File(FileUtils.getPhotoDir(context), "" + trackId.getId());
assertTrue(dir.exists()); assertTrue(dir.exists());
@@ -718,15 +718,15 @@ public class CustomContentProviderUtilsTest {
assertEquals(1, dir.list().length); assertEquals(1, dir.list().length);
// Update // Update
waypoint = contentProviderUtils.getMarker(waypointId); marker = contentProviderUtils.getMarker(markerId);
waypoint.setName(TEST_NAME_NEW); marker.setName(TEST_NAME_NEW);
waypoint.setDescription(TEST_DESC_NEW); marker.setDescription(TEST_DESC_NEW);
waypoint.setPhotoUrl(null); marker.setPhotoUrl(null);
contentProviderUtils.updateMarker(context, waypoint); contentProviderUtils.updateMarker(context, marker);
assertEquals(TEST_NAME_NEW, contentProviderUtils.getMarker(waypointId).getName()); assertEquals(TEST_NAME_NEW, contentProviderUtils.getMarker(markerId).getName());
assertEquals(TEST_DESC_NEW, contentProviderUtils.getMarker(waypointId).getDescription()); assertEquals(TEST_DESC_NEW, contentProviderUtils.getMarker(markerId).getDescription());
assertFalse(waypoint.hasPhoto()); assertFalse(marker.hasPhoto());
assertFalse(dir.exists()); assertFalse(dir.exists());
} }
@@ -734,33 +734,33 @@ public class CustomContentProviderUtilsTest {
* Tests the method {@link ContentProviderUtils#updateMarker(Context, Marker)}. * Tests the method {@link ContentProviderUtils#updateMarker(Context, Marker)}.
*/ */
@Test @Test
public void testUpdateWaypoint_delPhotoNotDir() throws IOException { public void testUpdateMarker_delPhotoNotDir() throws IOException {
// tests after update waypoint if user deletes the photo then file photo is deleted from the storage. Directory remains if there are more photos from other waypoints. // tests after update marker if user deletes the photo then file photo is deleted from the storage. Directory remains if there are more photos from other markers.
Track.Id trackId = new Track.Id(System.currentTimeMillis()); Track.Id trackId = new Track.Id(System.currentTimeMillis());
TestDataUtil.createTrackAndInsert(contentProviderUtils, trackId, 10); TestDataUtil.createTrackAndInsert(contentProviderUtils, trackId, 10);
// Insert two waypoints with photos. // Insert two markers with photos.
TrackPoint trackPoint = contentProviderUtils.getLastValidTrackPoint(trackId); TrackPoint trackPoint = contentProviderUtils.getLastValidTrackPoint(trackId);
Marker waypoint = TestDataUtil.createWaypointWithPhoto(context, trackId, trackPoint.getLocation()); Marker marker = TestDataUtil.createMarkerWithPhoto(context, trackId, trackPoint.getLocation());
waypoint.setDescription(TEST_DESC); marker.setDescription(TEST_DESC);
Marker otherWaypoint = TestDataUtil.createWaypointWithPhoto(context, trackId, trackPoint.getLocation()); Marker otherMarker = TestDataUtil.createMarkerWithPhoto(context, trackId, trackPoint.getLocation());
otherWaypoint.setDescription(TEST_DESC); otherMarker.setDescription(TEST_DESC);
Marker.Id waypointId = new Marker.Id(ContentUris.parseId(contentProviderUtils.insertMarker(waypoint))); Marker.Id markerId = new Marker.Id(ContentUris.parseId(contentProviderUtils.insertMarker(marker)));
contentProviderUtils.insertMarker(otherWaypoint); contentProviderUtils.insertMarker(otherMarker);
File dir = new File(FileUtils.getPhotoDir(context), "" + trackId.getId()); File dir = new File(FileUtils.getPhotoDir(context), "" + trackId.getId());
assertTrue(dir.exists()); assertTrue(dir.exists());
assertTrue(dir.isDirectory()); assertTrue(dir.isDirectory());
assertEquals(2, dir.list().length); assertEquals(2, dir.list().length);
// Update one waypoint deleting photo. // Update one marker deleting photo.
waypoint = contentProviderUtils.getMarker(waypointId); marker = contentProviderUtils.getMarker(markerId);
waypoint.setPhotoUrl(null); marker.setPhotoUrl(null);
contentProviderUtils.updateMarker(context, waypoint); contentProviderUtils.updateMarker(context, marker);
assertEquals(TEST_DESC, contentProviderUtils.getMarker(waypointId).getDescription()); assertEquals(TEST_DESC, contentProviderUtils.getMarker(markerId).getDescription());
assertFalse(waypoint.hasPhoto()); assertFalse(marker.hasPhoto());
assertTrue(dir.exists()); assertTrue(dir.exists());
assertTrue(dir.isDirectory()); assertTrue(dir.isDirectory());
assertEquals(1, dir.list().length); assertEquals(1, dir.list().length);
@@ -1,131 +0,0 @@
/*
* Copyright 2012 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package de.dennisguse.opentracks.io.file.importer;
import android.content.ContentUris;
import android.content.Context;
import android.location.Location;
import android.location.LocationManager;
import android.net.Uri;
import androidx.test.core.app.ApplicationProvider;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import java.text.SimpleDateFormat;
import java.time.ZoneOffset;
import java.util.Locale;
import java.util.SimpleTimeZone;
import java.util.TimeZone;
import de.dennisguse.opentracks.content.data.MarkerColumns;
import de.dennisguse.opentracks.content.data.Track;
import de.dennisguse.opentracks.content.data.TrackPoint;
import de.dennisguse.opentracks.content.provider.ContentProviderUtils;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.when;
/**
* Abstract class for testing file track importers.
*
* @author Jimmy Shih.
*/
public abstract class AbstractTestFileTrackImporter {
static final String TRACK_NAME_0 = "blablub";
static final String TRACK_DESCRIPTION_0 = "s'Laebe isch koi Schlotzer";
static final double TRACK_LATITUDE = 48.768364;
static final double TRACK_LONGITUDE = 9.177886;
static final double TRACK_ELEVATION = 324.0;
static final String TRACK_TIME_0 = "2010-04-22T18:21:00Z";
static final String TRACK_TIME_1 = "2010-04-22T18:21:50.123Z";
static final String TRACK_TIME_2 = "2010-04-22T18:23:00.123Z";
static final String TRACK_TIME_3 = "2010-04-22T18:24:50.123Z";
static final SimpleDateFormat DATE_FORMAT_0 = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss'Z'", Locale.US);
static final SimpleDateFormat DATE_FORMAT_1 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS", Locale.US);
static final long TRACK_POINT_ID_0 = 1;
static final long TRACK_POINT_ID_1 = 2;
static final long TRACK_POINT_ID_3 = 4;
private static final long WAYPOINT_ID_0 = 1;
private static final Uri WAYPOINT_ID_O_URI = ContentUris.appendId(MarkerColumns.CONTENT_URI.buildUpon(), WAYPOINT_ID_0).build();
protected final Context context = ApplicationProvider.getApplicationContext();
static {
// We can't omit the timezones in the test, otherwise it'll use the local timezone and fail depending on where the test runner is.
TimeZone utc = SimpleTimeZone.getTimeZone(ZoneOffset.UTC);
DATE_FORMAT_0.setTimeZone(utc);
DATE_FORMAT_1.setTimeZone(utc);
}
@Mock
public ContentProviderUtils contentProviderUtils;
TrackPoint createTrackPoint(int index, long time) {
Location trackPoint = new Location(LocationManager.GPS_PROVIDER);
trackPoint.setLatitude(TRACK_LATITUDE + index);
trackPoint.setLongitude(TRACK_LONGITUDE + index);
trackPoint.setAltitude(TRACK_ELEVATION + index);
trackPoint.setTime(time);
return new TrackPoint(trackPoint);
}
/**
* Expects the first track point to be added.
*
* @param trackPoint the trackPoint
* @param trackId the track id
* @param trackPointId the track point id
*/
protected void expectFirstTrackPoint(TrackPoint trackPoint, Track.Id trackId, long trackPointId) {
when(contentProviderUtils.bulkInsertTrackPoint(trackPoint != null ? (TrackPoint[]) any() : (TrackPoint[]) any(), eq(trackId))).thenReturn(1);
}
/**
* Expects the track to be updated.
*
* @param trackCaptor the track
* @param lastTrack true if it is the last track in the gpx
* @param trackId the track id
*/
protected void expectTrackUpdate(ArgumentCaptor<Track> trackCaptor, boolean lastTrack, Track.Id trackId) {
contentProviderUtils.updateTrack(trackCaptor.capture());
when(contentProviderUtils.insertMarker(any())).thenReturn(WAYPOINT_ID_O_URI);
if (lastTrack) {
// Return null to not add waypoints
when(contentProviderUtils.getTrack(trackId)).thenReturn(null);
}
}
protected void verifyTrack(Track track, String name, String description, long time) {
assertEquals(name, track.getName());
assertEquals(description, track.getDescription());
if (time != -1L) {
assertEquals(time, track.getTrackStatistics().getStartTime_ms());
}
}
}
@@ -138,7 +138,7 @@ public class TrackRecordingServiceTest {
@MediumTest @MediumTest
@Test @Test
public void testRecording_noTracks() throws Exception { public void testRecording_noTracks() throws TimeoutException {
// given // given
List<Track> tracks = contentProviderUtils.getTracks(); List<Track> tracks = contentProviderUtils.getTracks();
assertTrue(tracks.isEmpty()); assertTrue(tracks.isEmpty());
@@ -156,7 +156,7 @@ public class TrackRecordingServiceTest {
@MediumTest @MediumTest
@Test @Test
public void testRecording_oldTracks() throws Exception { public void testRecording_oldTracks() throws TimeoutException {
// given // given
createDummyTrack(trackId, -1L, false); createDummyTrack(trackId, -1L, false);
@@ -170,7 +170,7 @@ public class TrackRecordingServiceTest {
@MediumTest @MediumTest
@Test @Test
public void testRecording_serviceRestart_whileRecording() throws Exception { public void testRecording_serviceRestart_whileRecording() throws TimeoutException {
// given // given
createDummyTrack(trackId, -1L, true); createDummyTrack(trackId, -1L, true);
@@ -183,7 +183,7 @@ public class TrackRecordingServiceTest {
@MediumTest @MediumTest
@Test @Test
public void testRecording_pauseAndResume() throws Exception { public void testRecording_pauseAndResume() throws TimeoutException, InterruptedException {
// given // given
createDummyTrack(trackId, -1L, true); createDummyTrack(trackId, -1L, true);
TrackRecordingServiceInterface service = ((TrackRecordingServiceInterface) mServiceRule.bindService(createStartIntent(context))); TrackRecordingServiceInterface service = ((TrackRecordingServiceInterface) mServiceRule.bindService(createStartIntent(context)));
@@ -212,7 +212,7 @@ public class TrackRecordingServiceTest {
@MediumTest @MediumTest
@Test @Test
public void testRecording_resumeStoppedTrack() throws Exception { public void testRecording_resumeStoppedTrack() throws TimeoutException, InterruptedException {
// given // given
createDummyTrack(trackId, -1L, true); createDummyTrack(trackId, -1L, true);
TrackRecordingServiceInterface service = ((TrackRecordingServiceInterface) mServiceRule.bindService(createStartIntent(context))); TrackRecordingServiceInterface service = ((TrackRecordingServiceInterface) mServiceRule.bindService(createStartIntent(context)));
@@ -238,7 +238,7 @@ public class TrackRecordingServiceTest {
@Ignore("Sometimes fails on CI.") @Ignore("Sometimes fails on CI.")
@MediumTest @MediumTest
@Test @Test
public void testRecording_orphanedRecordingTrack() throws Exception { public void testRecording_orphanedRecordingTrack() throws TimeoutException {
// given // given
TrackRecordingServiceInterface service = ((TrackRecordingServiceInterface) mServiceRule.bindService(createStartIntent(context))); TrackRecordingServiceInterface service = ((TrackRecordingServiceInterface) mServiceRule.bindService(createStartIntent(context)));
@@ -254,7 +254,7 @@ public class TrackRecordingServiceTest {
@MediumTest @MediumTest
@Test @Test
public void testStartNewTrack_alreadyRecording() throws Exception { public void testStartNewTrack_alreadyRecording() throws TimeoutException {
// given // given
TrackRecordingServiceInterface service = ((TrackRecordingServiceInterface) mServiceRule.bindService(createStartIntent(context))); TrackRecordingServiceInterface service = ((TrackRecordingServiceInterface) mServiceRule.bindService(createStartIntent(context)));
service.startNewTrack(); service.startNewTrack();
@@ -274,7 +274,7 @@ public class TrackRecordingServiceTest {
@MediumTest @MediumTest
@Test @Test
public void testEndCurrentTrack_noRecording() throws Exception { public void testEndCurrentTrack_noRecording() throws TimeoutException {
// given // given
TrackRecordingServiceInterface service = ((TrackRecordingServiceInterface) mServiceRule.bindService(createStartIntent(context))); TrackRecordingServiceInterface service = ((TrackRecordingServiceInterface) mServiceRule.bindService(createStartIntent(context)));
assertFalse(service.isRecording()); assertFalse(service.isRecording());
@@ -290,21 +290,21 @@ public class TrackRecordingServiceTest {
@MediumTest @MediumTest
@Test @Test
public void testInsertWaypointMarker_noRecordingTrack() throws Exception { public void testInsertWaypointMarker_noRecordingTrack() throws TimeoutException {
// given // given
TrackRecordingServiceInterface service = ((TrackRecordingServiceInterface) mServiceRule.bindService(createStartIntent(context))); TrackRecordingServiceInterface service = ((TrackRecordingServiceInterface) mServiceRule.bindService(createStartIntent(context)));
assertFalse(service.isRecording()); assertFalse(service.isRecording());
// when // when
Marker.Id waypointId = service.insertMarker(null, null, null, null); Marker.Id markerId = service.insertMarker(null, null, null, null);
// then // then
assertNull(waypointId); assertNull(markerId);
} }
@MediumTest @MediumTest
@Test @Test
public void testInsertWaypointMarker_validWaypoint() throws Exception { public void testInsertWaypointMarker_validWaypoint() throws TimeoutException, InterruptedException {
// given // given
TrackRecordingServiceInterface service = ((TrackRecordingServiceInterface) mServiceRule.bindService(createStartIntent(context))); TrackRecordingServiceInterface service = ((TrackRecordingServiceInterface) mServiceRule.bindService(createStartIntent(context)));
service.startNewTrack(); service.startNewTrack();
@@ -313,11 +313,11 @@ public class TrackRecordingServiceTest {
Track.Id trackId = service.getRecordingTrackId(); Track.Id trackId = service.getRecordingTrackId();
// when // when
Marker.Id waypointId = service.insertMarker(null, null, null, null); Marker.Id markerId = service.insertMarker(null, null, null, null);
// then // then
assertNotEquals(-1L, waypointId); assertNotEquals(-1L, markerId);
Marker wpt = contentProviderUtils.getMarker(waypointId); Marker wpt = contentProviderUtils.getMarker(markerId);
assertEquals(context.getString(R.string.marker_icon_url), wpt.getIcon()); assertEquals(context.getString(R.string.marker_icon_url), wpt.getIcon());
assertEquals(context.getString(R.string.marker_name_format, 1), wpt.getName()); assertEquals(context.getString(R.string.marker_name_format, 1), wpt.getName());
assertEquals(trackId, wpt.getTrackId()); assertEquals(trackId, wpt.getTrackId());