forked from upstream-mirrors/OpenTracks
Fix unit tests with TrackPathDescriptor.
In MapOverlay, for testing, expose a getter and a setter for TrackPathDescriptor instead of newPath and getLastPath. In SingleColorTrackPathPainter, refactor "new Path" to a newPath method so that tests can override the newPath method to provide a mockPath.
This commit is contained in:
@@ -16,9 +16,11 @@
|
||||
package com.google.android.apps.mytracks;
|
||||
|
||||
import com.google.android.apps.mytracks.content.Waypoint;
|
||||
import com.google.android.apps.mytracks.maps.SingleColorTrackPathPainter;
|
||||
import com.google.android.maps.MapView;
|
||||
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Path;
|
||||
import android.location.Location;
|
||||
import android.test.AndroidTestCase;
|
||||
|
||||
@@ -38,12 +40,22 @@ public class MapOverlayTest extends AndroidTestCase {
|
||||
super.setUp();
|
||||
canvas = new Canvas();
|
||||
myTracksOverlay = new MockMyTracksOverlay(getContext());
|
||||
|
||||
// Enable drawing.
|
||||
myTracksOverlay.setTrackDrawingEnabled(true);
|
||||
|
||||
// Set a TrackPathPainter with a MockPath.
|
||||
myTracksOverlay.setTrackPathPainter(new SingleColorTrackPathPainter(getContext()) {
|
||||
@Override
|
||||
public Path newPath() {
|
||||
return new MockPath();
|
||||
}
|
||||
});
|
||||
|
||||
mockView = null;
|
||||
}
|
||||
|
||||
public void testAddLocation() throws Exception {
|
||||
public void testAddLocation() throws Exception {
|
||||
Location location = new Location("gps");
|
||||
location.setLatitude(10);
|
||||
location.setLongitude(20);
|
||||
@@ -56,18 +68,21 @@ public class MapOverlayTest extends AndroidTestCase {
|
||||
myTracksOverlay.addLocation(location);
|
||||
assertEquals(2, myTracksOverlay.getNumLocations());
|
||||
assertEquals(0, myTracksOverlay.getNumWaypoints());
|
||||
assertNull(myTracksOverlay.getLastPath());
|
||||
assertNull(myTracksOverlay.getTrackPathPainter().getLastPath());
|
||||
|
||||
// Draw and make sure that we don't lose any point.
|
||||
myTracksOverlay.draw(canvas, mockView, false);
|
||||
assertEquals(2, myTracksOverlay.getNumLocations());
|
||||
assertEquals(0, myTracksOverlay.getNumWaypoints());
|
||||
assertNotNull(myTracksOverlay.getLastPath());
|
||||
assertNotNull(myTracksOverlay.getTrackPathPainter().getLastPath());
|
||||
assertTrue(myTracksOverlay.getTrackPathPainter().getLastPath() instanceof MockPath);
|
||||
MockPath path = (MockPath) myTracksOverlay.getTrackPathPainter().getLastPath();
|
||||
assertEquals(2, path.totalPoints);
|
||||
|
||||
myTracksOverlay.draw(canvas, mockView, true);
|
||||
assertEquals(2, myTracksOverlay.getNumLocations());
|
||||
assertEquals(0, myTracksOverlay.getNumWaypoints());
|
||||
assertNotNull(myTracksOverlay.getLastPath());
|
||||
assertNotNull(myTracksOverlay.getTrackPathPainter().getLastPath());
|
||||
}
|
||||
|
||||
public void testClearPoints() throws Exception {
|
||||
@@ -100,7 +115,7 @@ public class MapOverlayTest extends AndroidTestCase {
|
||||
myTracksOverlay.addWaypoint(waypoint);
|
||||
assertEquals(1, myTracksOverlay.getNumWaypoints());
|
||||
assertEquals(0, myTracksOverlay.getNumLocations());
|
||||
assertNull(myTracksOverlay.getLastPath());
|
||||
assertNull(myTracksOverlay.getTrackPathPainter().getLastPath());
|
||||
|
||||
final int waypoints = 10;
|
||||
for (int i = 0; i < waypoints; ++i) {
|
||||
@@ -110,7 +125,7 @@ public class MapOverlayTest extends AndroidTestCase {
|
||||
}
|
||||
assertEquals(1 + waypoints, myTracksOverlay.getNumWaypoints());
|
||||
assertEquals(0, myTracksOverlay.getNumLocations());
|
||||
assertNull(myTracksOverlay.getLastPath());
|
||||
assertNull(myTracksOverlay.getTrackPathPainter().getLastPath());
|
||||
}
|
||||
|
||||
public void testClearWaypoints() throws Exception {
|
||||
@@ -144,15 +159,18 @@ public class MapOverlayTest extends AndroidTestCase {
|
||||
// Shadow.
|
||||
myTracksOverlay.draw(canvas, mockView, true);
|
||||
// We don't expect to do anything if
|
||||
assertNull(myTracksOverlay.getLastPath());
|
||||
assertNull(myTracksOverlay.getTrackPathPainter().getLastPath());
|
||||
assertEquals(40, myTracksOverlay.getNumWaypoints());
|
||||
assertEquals(100, myTracksOverlay.getNumLocations());
|
||||
|
||||
// No shadow.
|
||||
myTracksOverlay.draw(canvas, mockView, false);
|
||||
assertNotNull(myTracksOverlay.getLastPath());
|
||||
assertNotNull(myTracksOverlay.getTrackPathPainter().getLastPath());
|
||||
assertTrue(myTracksOverlay.getTrackPathPainter().getLastPath() instanceof MockPath);
|
||||
MockPath path = (MockPath) myTracksOverlay.getTrackPathPainter().getLastPath();
|
||||
assertEquals(40, myTracksOverlay.getNumWaypoints());
|
||||
assertEquals(100, myTracksOverlay.getNumLocations());
|
||||
assertEquals(100, path.totalPoints);
|
||||
// TODO: Check the points from the path (and the segments).
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ import com.google.android.maps.MapView;
|
||||
import com.google.android.maps.Projection;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Path;
|
||||
import android.graphics.Rect;
|
||||
|
||||
/**
|
||||
@@ -32,7 +31,7 @@ import android.graphics.Rect;
|
||||
* {@class MapView}.
|
||||
*/
|
||||
public class MockMyTracksOverlay extends MapOverlay {
|
||||
|
||||
|
||||
private Projection mockProjection;
|
||||
|
||||
public MockMyTracksOverlay(Context context) {
|
||||
@@ -49,9 +48,4 @@ public class MockMyTracksOverlay extends MapOverlay {
|
||||
public Rect getMapViewRect(MapView mapView) {
|
||||
return new Rect(0, 0, 100, 100);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Path newPath() {
|
||||
return new MockPath();
|
||||
}
|
||||
}
|
||||
+5
-1
@@ -35,7 +35,10 @@ public class TrackPathDescriptorDynamicSpeedTest extends TrackPathPainterTestCas
|
||||
myTracksOverlay.addLocation(location);
|
||||
}
|
||||
|
||||
TrackPathPainter painter = new DynamicSpeedTrackPathPainter(getContext(), new DynamicSpeedTrackPathDescriptor(getContext()));
|
||||
TrackPathPainter painter = new DynamicSpeedTrackPathPainter(
|
||||
getContext(), new DynamicSpeedTrackPathDescriptor(getContext()));
|
||||
myTracksOverlay.setTrackPathPainter(painter);
|
||||
|
||||
int startLocationIdx = 0;
|
||||
Boolean alwaysVisible = true;
|
||||
|
||||
@@ -43,6 +46,7 @@ public class TrackPathDescriptorDynamicSpeedTest extends TrackPathPainterTestCas
|
||||
painter.updatePath(myTracksOverlay.getMapProjection(mockView),
|
||||
myTracksOverlay.getMapViewRect(mockView), startLocationIdx, alwaysVisible,
|
||||
myTracksOverlay.getPoints());
|
||||
assertNotNull(myTracksOverlay.getTrackPathPainter().getLastPath());
|
||||
painter.drawTrack(canvas);
|
||||
}
|
||||
}
|
||||
|
||||
+5
-1
@@ -35,7 +35,10 @@ public class TrackPathDescriptorFixedSpeedTest extends TrackPathPainterTestCase
|
||||
myTracksOverlay.addLocation(location);
|
||||
}
|
||||
|
||||
TrackPathPainter painter = new DynamicSpeedTrackPathPainter(getContext(), new FixedSpeedTrackPathDescriptor(getContext()));
|
||||
TrackPathPainter painter = new DynamicSpeedTrackPathPainter(
|
||||
getContext(), new FixedSpeedTrackPathDescriptor(getContext()));
|
||||
myTracksOverlay.setTrackPathPainter(painter);
|
||||
|
||||
int startLocationIdx = 0;
|
||||
Boolean alwaysVisible = true;
|
||||
|
||||
@@ -43,6 +46,7 @@ public class TrackPathDescriptorFixedSpeedTest extends TrackPathPainterTestCase
|
||||
painter.updatePath(myTracksOverlay.getMapProjection(mockView),
|
||||
myTracksOverlay.getMapViewRect(mockView), startLocationIdx, alwaysVisible,
|
||||
myTracksOverlay.getPoints());
|
||||
assertNotNull(myTracksOverlay.getTrackPathPainter().getLastPath());
|
||||
painter.drawTrack(canvas);
|
||||
}
|
||||
}
|
||||
|
||||
+2
@@ -63,6 +63,7 @@ public class TrackPathPainterFactoryTest extends TrackPathPainterTestCase {
|
||||
Boolean alwaysVisible = true;
|
||||
|
||||
TrackPathPainter painter = TrackPathPainterFactory.getTrackPathPainter(context);
|
||||
myTracksOverlay.setTrackPathPainter(painter);
|
||||
|
||||
assertNotNull(painter);
|
||||
assertTrue(c.isInstance(painter));
|
||||
@@ -70,6 +71,7 @@ public class TrackPathPainterFactoryTest extends TrackPathPainterTestCase {
|
||||
painter.updatePath(myTracksOverlay.getMapProjection(mockView),
|
||||
myTracksOverlay.getMapViewRect(mockView), startLocationIdx, alwaysVisible,
|
||||
myTracksOverlay.getPoints());
|
||||
assertNotNull(myTracksOverlay.getTrackPathPainter().getLastPath());
|
||||
painter.drawTrack(canvas);
|
||||
}
|
||||
}
|
||||
|
||||
+3
@@ -36,6 +36,8 @@ public class TrackPathPainterSingleColorTest extends TrackPathPainterTestCase {
|
||||
}
|
||||
|
||||
TrackPathPainter painter = new SingleColorTrackPathPainter(getContext());
|
||||
myTracksOverlay.setTrackPathPainter(painter);
|
||||
|
||||
int startLocationIdx = 0;
|
||||
Boolean alwaysVisible = true;
|
||||
|
||||
@@ -43,6 +45,7 @@ public class TrackPathPainterSingleColorTest extends TrackPathPainterTestCase {
|
||||
painter.updatePath(myTracksOverlay.getMapProjection(mockView),
|
||||
myTracksOverlay.getMapViewRect(mockView), startLocationIdx, alwaysVisible,
|
||||
myTracksOverlay.getPoints());
|
||||
assertNotNull(myTracksOverlay.getTrackPathPainter().getLastPath());
|
||||
painter.drawTrack(canvas);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user