mirror of
https://codeberg.org/OpenTracksApp/OpenTracks.git
synced 2026-10-08 12:23:06 +02:00
Fix unit test errors in DocsHelper_AddTrackRowTest.java
DocsHelper_AddTrackRowTest is using a MockContext, which cannot be used to call DateFormat.getDateFormat(context). Refactor a getDisplayDate method in DocsHelper and allow the test to override the method. Also update .hgignore to AnnotationProcessor.log.
This commit is contained in:
@@ -4,7 +4,7 @@ syntax:glob
|
|||||||
*/gen/**
|
*/gen/**
|
||||||
*/proguard/**
|
*/proguard/**
|
||||||
.metadata
|
.metadata
|
||||||
MyTracksTest/annotations.log
|
MyTracksTest/AnnotationProcessor.log
|
||||||
**/*.pyc
|
**/*.pyc
|
||||||
**/*.pyo
|
**/*.pyo
|
||||||
syntax: glob
|
syntax: glob
|
||||||
|
|||||||
@@ -275,7 +275,6 @@ public class DocsHelper {
|
|||||||
public void addTrackRow(Context context, AuthManager trixAuth,
|
public void addTrackRow(Context context, AuthManager trixAuth,
|
||||||
String spreadsheetId, String worksheetId, Track track,
|
String spreadsheetId, String worksheetId, Track track,
|
||||||
boolean metricUnits) throws IOException {
|
boolean metricUnits) throws IOException {
|
||||||
|
|
||||||
String worksheetUri = String.format(DOCS_SPREADSHEET_URL_FORMAT,
|
String worksheetUri = String.format(DOCS_SPREADSHEET_URL_FORMAT,
|
||||||
spreadsheetId, worksheetId);
|
spreadsheetId, worksheetId);
|
||||||
TripStatistics stats = track.getStatistics();
|
TripStatistics stats = track.getStatistics();
|
||||||
@@ -287,16 +286,11 @@ public class DocsHelper {
|
|||||||
String elevationUnit = context.getString(metricUnits ?
|
String elevationUnit = context.getString(metricUnits ?
|
||||||
R.string.meter : R.string.feet);
|
R.string.meter : R.string.feet);
|
||||||
|
|
||||||
java.text.DateFormat dateFormat = DateFormat.getDateFormat(context);
|
|
||||||
java.text.DateFormat timeFormat = DateFormat.getTimeFormat(context);
|
|
||||||
Date startTime = new Date(stats.getStartTime());
|
|
||||||
String dateString = dateFormat.format(startTime) + " " + timeFormat.format(startTime);
|
|
||||||
|
|
||||||
// Prepare the Post-Text we are going to send.
|
// Prepare the Post-Text we are going to send.
|
||||||
DocsTagBuilder tagBuilder = new DocsTagBuilder(metricUnits)
|
DocsTagBuilder tagBuilder = new DocsTagBuilder(metricUnits)
|
||||||
.append("name", track.getName())
|
.append("name", track.getName())
|
||||||
.append("description", track.getDescription())
|
.append("description", track.getDescription())
|
||||||
.append("date", dateString)
|
.append("date", getDisplayDate(context, stats.getStartTime()))
|
||||||
.append("totaltime", StringUtils.formatTimeAlwaysShowingHours(
|
.append("totaltime", StringUtils.formatTimeAlwaysShowingHours(
|
||||||
stats.getTotalTime()))
|
stats.getTotalTime()))
|
||||||
.append("movingtime", StringUtils.formatTimeAlwaysShowingHours(
|
.append("movingtime", StringUtils.formatTimeAlwaysShowingHours(
|
||||||
@@ -336,6 +330,21 @@ public class DocsHelper {
|
|||||||
Log.i(Constants.TAG, "Post finished.");
|
Log.i(Constants.TAG, "Post finished.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the display string for a time based on the phone's setting.
|
||||||
|
*
|
||||||
|
* @param context the context to obtain the phone's setting.
|
||||||
|
* @param time the time
|
||||||
|
* @return the display string of the time
|
||||||
|
*/
|
||||||
|
protected String getDisplayDate(Context context, long time) {
|
||||||
|
java.text.DateFormat dateFormat = DateFormat.getDateFormat(context);
|
||||||
|
java.text.DateFormat timeFormat = DateFormat.getTimeFormat(context);
|
||||||
|
Date startTime = new Date(time);
|
||||||
|
String dateString = dateFormat.format(startTime) + " " + timeFormat.format(startTime);
|
||||||
|
return dateString;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes spreadsheet row data to the indicated worksheet.
|
* Writes spreadsheet row data to the indicated worksheet.
|
||||||
*
|
*
|
||||||
|
|||||||
+14
-4
@@ -40,6 +40,7 @@ import junit.framework.TestCase;
|
|||||||
*/
|
*/
|
||||||
public class DocsHelper_AddTrackRowTest extends TestCase {
|
public class DocsHelper_AddTrackRowTest extends TestCase {
|
||||||
private static final long TIME = 1288721514000L;
|
private static final long TIME = 1288721514000L;
|
||||||
|
private static final DateFormat DATE_FORMAT = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
|
||||||
|
|
||||||
private static class StringWritingDocsHelper extends DocsHelper {
|
private static class StringWritingDocsHelper extends DocsHelper {
|
||||||
String writtenSheetUri = null;
|
String writtenSheetUri = null;
|
||||||
@@ -54,16 +55,20 @@ public class DocsHelper_AddTrackRowTest extends TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testAddTrackRow_imperial() throws Exception {
|
public void testAddTrackRow_imperial() throws Exception {
|
||||||
StringWritingDocsHelper docsHelper = new StringWritingDocsHelper();
|
StringWritingDocsHelper docsHelper = new StringWritingDocsHelper() {
|
||||||
|
@Override
|
||||||
|
protected String getDisplayDate(Context context, long time) {
|
||||||
|
return DATE_FORMAT.format(new Date(TIME));
|
||||||
|
}
|
||||||
|
};
|
||||||
addTrackRow(docsHelper, false);
|
addTrackRow(docsHelper, false);
|
||||||
|
|
||||||
DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
|
|
||||||
String expectedData =
|
String expectedData =
|
||||||
"<entry xmlns='http://www.w3.org/2005/Atom' "
|
"<entry xmlns='http://www.w3.org/2005/Atom' "
|
||||||
+ "xmlns:gsx='http://schemas.google.com/spreadsheets/2006/extended'>"
|
+ "xmlns:gsx='http://schemas.google.com/spreadsheets/2006/extended'>"
|
||||||
+ "<gsx:name><![CDATA[trackName]]></gsx:name>"
|
+ "<gsx:name><![CDATA[trackName]]></gsx:name>"
|
||||||
+ "<gsx:description><![CDATA[trackDescription]]></gsx:description>"
|
+ "<gsx:description><![CDATA[trackDescription]]></gsx:description>"
|
||||||
+ "<gsx:date><![CDATA[" + dateFormat.format(new Date(TIME)) + "]]></gsx:date>"
|
+ "<gsx:date><![CDATA[" + DATE_FORMAT.format(new Date(TIME)) + "]]></gsx:date>"
|
||||||
+ "<gsx:totaltime><![CDATA[0:00:05]]></gsx:totaltime>"
|
+ "<gsx:totaltime><![CDATA[0:00:05]]></gsx:totaltime>"
|
||||||
+ "<gsx:movingtime><![CDATA[0:00:04]]></gsx:movingtime>"
|
+ "<gsx:movingtime><![CDATA[0:00:04]]></gsx:movingtime>"
|
||||||
+ "<gsx:distance><![CDATA[12.43]]></gsx:distance>"
|
+ "<gsx:distance><![CDATA[12.43]]></gsx:distance>"
|
||||||
@@ -89,7 +94,12 @@ public class DocsHelper_AddTrackRowTest extends TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testAddTrackRow_metric() throws Exception {
|
public void testAddTrackRow_metric() throws Exception {
|
||||||
StringWritingDocsHelper docsHelper = new StringWritingDocsHelper();
|
StringWritingDocsHelper docsHelper = new StringWritingDocsHelper() {
|
||||||
|
@Override
|
||||||
|
protected String getDisplayDate(Context context, long time) {
|
||||||
|
return DATE_FORMAT.format(new Date(TIME));
|
||||||
|
}
|
||||||
|
};
|
||||||
addTrackRow(docsHelper, true);
|
addTrackRow(docsHelper, true);
|
||||||
|
|
||||||
// The imperial test verifies that the tags come out in the proper order,
|
// The imperial test verifies that the tags come out in the proper order,
|
||||||
|
|||||||
Reference in New Issue
Block a user