diff --git a/MyTracks/src/com/google/android/apps/mytracks/io/maps/SendMapsAsyncTask.java b/MyTracks/src/com/google/android/apps/mytracks/io/maps/SendMapsAsyncTask.java
index 00c866922..0bf3d098a 100644
--- a/MyTracks/src/com/google/android/apps/mytracks/io/maps/SendMapsAsyncTask.java
+++ b/MyTracks/src/com/google/android/apps/mytracks/io/maps/SendMapsAsyncTask.java
@@ -34,6 +34,7 @@ import com.google.android.apps.mytracks.util.LocationUtils;
import com.google.android.apps.mytracks.util.UnitConversions;
import com.google.android.common.gdata.AndroidXmlParserFactory;
import com.google.android.maps.mytracks.R;
+import com.google.common.annotations.VisibleForTesting;
import com.google.wireless.gdata.client.GDataClient;
import com.google.wireless.gdata.client.HttpException;
import com.google.wireless.gdata.parser.ParseException;
@@ -73,8 +74,10 @@ public class SendMapsAsyncTask extends AbstractSendAsyncTask {
private static final int MAX_POINTS_PER_UPLOAD = 500;
private static final int PROGRESS_FETCH_MAP_ID = 5;
- private static final int PROGRESS_UPLOAD_DATA_MIN = 10;
- private static final int PROGRESS_UPLOAD_DATA_MAX = 90;
+ @VisibleForTesting
+ static final int PROGRESS_UPLOAD_DATA_MIN = 10;
+ @VisibleForTesting
+ static final int PROGRESS_UPLOAD_DATA_MAX = 90;
private static final int PROGRESS_UPLOAD_WAYPOINTS = 95;
private static final int PROGRESS_COMPLETE = 100;
@@ -83,8 +86,8 @@ public class SendMapsAsyncTask extends AbstractSendAsyncTask {
private final long trackId;
private final Account account;
private final String chooseMapId;
- private final Context context;
private final MyTracksProviderUtils myTracksProviderUtils;
+ private final Context context;
private final GDataClient gDataClient;
private final MapsClient mapsClient;
@@ -94,15 +97,25 @@ public class SendMapsAsyncTask extends AbstractSendAsyncTask {
private String mapId;
int currentSegment;
+ public SendMapsAsyncTask(SendMapsActivity activity, long trackId, Account account,
+ String chooseMapId) {
+ this(activity, trackId, account, chooseMapId, MyTracksProviderUtils.Factory.get(activity
+ .getApplicationContext()));
+ }
+
+ /**
+ * This constructor is created for test.
+ */
+ @VisibleForTesting
public SendMapsAsyncTask (
- SendMapsActivity activity, long trackId, Account account, String chooseMapId) {
+ SendMapsActivity activity, long trackId, Account account, String chooseMapId, MyTracksProviderUtils myTracksProviderUtils) {
super(activity);
this.trackId = trackId;
this.account = account;
this.chooseMapId = chooseMapId;
-
+ this.myTracksProviderUtils = myTracksProviderUtils;
context = activity.getApplicationContext();
- myTracksProviderUtils = MyTracksProviderUtils.Factory.get(context);
+
gDataClient = GDataClientFactory.getGDataClient(context);
mapsClient = new MapsClient(
gDataClient, new XmlMapsGDataParserFactory(new AndroidXmlParserFactory()));
@@ -201,7 +214,8 @@ public class SendMapsAsyncTask extends AbstractSendAsyncTask {
* @param track the Track
* @return true if able to fetch the mapId variable.
*/
- private boolean fetchSendMapId(Track track) {
+ @VisibleForTesting
+ boolean fetchSendMapId(Track track) {
if (isCancelled()) {
return false;
}
@@ -239,7 +253,8 @@ public class SendMapsAsyncTask extends AbstractSendAsyncTask {
* @param track the track
* @return true if success.
*/
- private boolean uploadAllTrackPoints(Track track) {
+ @VisibleForTesting
+ boolean uploadAllTrackPoints(Track track) {
Cursor locationsCursor = null;
try {
SharedPreferences prefs = context.getSharedPreferences(
@@ -313,9 +328,8 @@ public class SendMapsAsyncTask extends AbstractSendAsyncTask {
if (lastLocation != null) {
distances.add(tripStatisticsBuilder.getStatistics().getTotalDistance());
elevations.add(elevationBuffer.getAverage());
- DescriptionGenerator descriptionGenerator = new DescriptionGeneratorImpl(context);
- track.setDescription("
" + track.getDescription() + "
"
- + descriptionGenerator.generateTrackDescription(track, distances, elevations) + "
");
+
+ track.setDescription(getTrackDescription(track, distances, elevations));
if (!uploadMarker(context.getString(R.string.marker_label_end, track.getName()),
track.getDescription(), END_ICON_URL, lastLocation)) {
Log.d(TAG, "Unable to create an end marker");
@@ -330,6 +344,21 @@ public class SendMapsAsyncTask extends AbstractSendAsyncTask {
}
}
+ /**
+ * Gets the description of a track.
+ *
+ * @param track the track
+ * @param distances distance vectors
+ * @param elevations elevation vectors
+ * @return the description of a track.
+ */
+ @VisibleForTesting
+ String getTrackDescription(Track track, Vector distances, Vector elevations) {
+ DescriptionGenerator descriptionGenerator = new DescriptionGeneratorImpl(context);
+ return "" + track.getDescription() + "
"
+ + descriptionGenerator.generateTrackDescription(track, distances, elevations) + "
";
+ }
+
/**
* Prepares and uploads a list of locations from a track.
*
@@ -338,7 +367,8 @@ public class SendMapsAsyncTask extends AbstractSendAsyncTask {
* @param lastBatch true if it is the last batch of locations
* @return true if success.
*/
- private boolean prepareAndUploadPoints(Track track, List locations, boolean lastBatch) {
+ @VisibleForTesting
+ boolean prepareAndUploadPoints(Track track, List locations, boolean lastBatch) {
// Prepare locations
ArrayList