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:
@@ -35,7 +35,6 @@ import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Path;
|
||||
import android.graphics.Point;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.Drawable;
|
||||
@@ -305,17 +304,17 @@ public class MapOverlay extends Overlay implements OnSharedPreferenceChangeListe
|
||||
int cy = mapView.getMapCenter().getLatitudeE6();
|
||||
return new Rect(cx - w / 2, cy - h / 2, cx + w / 2, cy + h / 2);
|
||||
}
|
||||
|
||||
// Visible for testing.
|
||||
Path newPath() {
|
||||
return new Path();
|
||||
}
|
||||
|
||||
// Visible for testing.
|
||||
public Path getLastPath() {
|
||||
return trackPathPainter.getLastPath();
|
||||
|
||||
// Visible for testing
|
||||
public TrackPathPainter getTrackPathPainter() {
|
||||
return trackPathPainter;
|
||||
}
|
||||
|
||||
// Visible for testing
|
||||
public void setTrackPathPainter(TrackPathPainter trackPathPainter) {
|
||||
this.trackPathPainter = trackPathPainter;
|
||||
}
|
||||
|
||||
private void drawWaypoints(Canvas canvas, Projection projection) {
|
||||
synchronized (waypoints) {;
|
||||
for (Waypoint wpt : waypoints) {
|
||||
|
||||
@@ -57,7 +57,7 @@ public class SingleColorTrackPathPainter implements TrackPathPainter {
|
||||
final Point pt = new Point();
|
||||
// Loop over track points.
|
||||
int numPoints = points.size();
|
||||
path = new Path();
|
||||
path = newPath();
|
||||
path.incReserve(numPoints);
|
||||
|
||||
for (int i = startLocationIdx; i < numPoints ; ++i) {
|
||||
@@ -104,4 +104,9 @@ public class SingleColorTrackPathPainter implements TrackPathPainter {
|
||||
public Path getLastPath() {
|
||||
return path;
|
||||
}
|
||||
|
||||
// Visible for testing
|
||||
public Path newPath() {
|
||||
return new Path();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user