forked from upstream-mirrors/OpenTracks
Be more explicit in testing the XML output of GpxTrackWriter.
Instead of producing the comparison strings in the tester just as they are produced in the tested code, use string literals, thus actually testing that the formatting code is working as expected.
This commit is contained in:
@@ -37,10 +37,10 @@ import java.util.TimeZone;
|
|||||||
*/
|
*/
|
||||||
public class GpxTrackWriter implements TrackFormatWriter {
|
public class GpxTrackWriter implements TrackFormatWriter {
|
||||||
|
|
||||||
static final int LATLONG_FORMAT = Location.FORMAT_DEGREES;
|
private static final int LATLONG_FORMAT = Location.FORMAT_DEGREES;
|
||||||
static final DecimalFormat ELEVATION_FORMATTER =
|
private static final DecimalFormat ELEVATION_FORMATTER =
|
||||||
new DecimalFormat("#.#");
|
new DecimalFormat("#.#");
|
||||||
static final SimpleDateFormat TIMESTAMP_FORMATTER =
|
private static final SimpleDateFormat TIMESTAMP_FORMATTER =
|
||||||
new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
|
new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
|
||||||
static {
|
static {
|
||||||
TIMESTAMP_FORMATTER.setTimeZone(TimeZone.getTimeZone("UTC"));
|
TIMESTAMP_FORMATTER.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||||
|
|||||||
@@ -30,62 +30,41 @@ public class GpxTrackWriterTest extends TrackFormatWriterTest {
|
|||||||
assertEquals(Long.toString(TRACK_ID),
|
assertEquals(Long.toString(TRACK_ID),
|
||||||
getChildTextValue(trackTag, "number"));
|
getChildTextValue(trackTag, "number"));
|
||||||
List<Element> segmentTags = getChildElements(trackTag, "trkseg", 2);
|
List<Element> segmentTags = getChildElements(trackTag, "trkseg", 2);
|
||||||
Element segment1Tag = segmentTags.get(0);
|
List<Element> segPointTags = getChildElements(segmentTags.get(0), "trkpt", 2);
|
||||||
Element segment2Tag = segmentTags.get(1);
|
assertTagMatchesLocation(segPointTags.get(0),
|
||||||
List<Element> seg1PointTags = getChildElements(segment1Tag, "trkpt", 2);
|
"0", "0", "1970-01-01T02:46:40Z", "0");
|
||||||
List<Element> seg2PointTags = getChildElements(segment2Tag, "trkpt", 2);
|
assertTagMatchesLocation(segPointTags.get(1),
|
||||||
assertTagsMatchPoints(seg1PointTags, location1, location2);
|
"1", "-1", "1970-01-01T02:46:41Z", "5000000");
|
||||||
assertTagsMatchPoints(seg2PointTags, location3, location4);
|
|
||||||
|
segPointTags = getChildElements(segmentTags.get(1), "trkpt", 2);
|
||||||
|
assertTagMatchesLocation(segPointTags.get(0),
|
||||||
|
"2", "-2", "1970-01-01T02:46:42Z", "10000000");
|
||||||
|
assertTagMatchesLocation(segPointTags.get(1),
|
||||||
|
"3", "-3", "1970-01-01T02:46:43Z", "15000000");
|
||||||
|
|
||||||
List<Element> waypointTags = getChildElements(gpxTag, "wpt", 2);
|
List<Element> waypointTags = getChildElements(gpxTag, "wpt", 2);
|
||||||
assertTagsMatchWaypoints(waypointTags, wp1, wp2);
|
Element wptTag = waypointTags.get(0);
|
||||||
|
assertEquals(WAYPOINT1_NAME, getChildTextValue(wptTag, "name"));
|
||||||
|
assertEquals(WAYPOINT1_DESCRIPTION, getChildTextValue(wptTag, "desc"));
|
||||||
|
assertTagMatchesLocation(wptTag,
|
||||||
|
"1", "-1", "1970-01-01T02:46:41Z", "5000000");
|
||||||
|
|
||||||
|
wptTag = waypointTags.get(1);
|
||||||
|
assertEquals(WAYPOINT2_NAME, getChildTextValue(wptTag, "name"));
|
||||||
|
assertEquals(WAYPOINT2_DESCRIPTION, getChildTextValue(wptTag, "desc"));
|
||||||
|
assertTagMatchesLocation(wptTag,
|
||||||
|
"2", "-2", "1970-01-01T02:46:42Z", "10000000");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Asserts that the given tags describe the given waypoints, in the same
|
* Asserts that the given tag describes the location given by the
|
||||||
* order.
|
* Strings lat, lon, time, and ele.
|
||||||
*/
|
*/
|
||||||
protected void assertTagsMatchWaypoints(List<Element> tags, Waypoint... wps) {
|
private void assertTagMatchesLocation(Element tag, String lat,
|
||||||
assertEquals(wps.length, tags.size());
|
String lon, String time, String ele) {
|
||||||
for (int i = 0; i < wps.length; i++) {
|
assertEquals(lat, tag.getAttribute("lat"));
|
||||||
Element tag = tags.get(i);
|
assertEquals(lon, tag.getAttribute("lon"));
|
||||||
Waypoint wp = wps[i];
|
assertEquals(time, getChildTextValue(tag, "time"));
|
||||||
Location loc = wp.getLocation();
|
assertEquals(ele, getChildTextValue(tag, "ele"));
|
||||||
|
|
||||||
assertTagMatchesLocation(tag, loc);
|
|
||||||
|
|
||||||
assertEquals(wp.getName(), getChildTextValue(tag, "name"));
|
|
||||||
assertEquals(wp.getDescription(), getChildTextValue(tag, "desc"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Asserts that the given tags describe the given points, in the same order.
|
|
||||||
*/
|
|
||||||
protected void assertTagsMatchPoints(List<Element> tags, Location... locs) {
|
|
||||||
assertEquals(locs.length, tags.size());
|
|
||||||
for (int i = 0; i < locs.length; i++) {
|
|
||||||
Element tag = tags.get(i);
|
|
||||||
Location loc = locs[i];
|
|
||||||
|
|
||||||
assertTagMatchesLocation(tag, loc);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Asserts that the given tag describes the given location.
|
|
||||||
*/
|
|
||||||
private void assertTagMatchesLocation(Element tag, Location loc) {
|
|
||||||
assertEquals(
|
|
||||||
Location.convert(loc.getLatitude(), GpxTrackWriter.LATLONG_FORMAT),
|
|
||||||
tag.getAttribute("lat"));
|
|
||||||
assertEquals(
|
|
||||||
Location.convert(loc.getLongitude(), GpxTrackWriter.LATLONG_FORMAT),
|
|
||||||
tag.getAttribute("lon"));
|
|
||||||
assertEquals(
|
|
||||||
GpxTrackWriter.TIMESTAMP_FORMATTER.format(new Date(loc.getTime())),
|
|
||||||
getChildTextValue(tag, "time"));
|
|
||||||
assertEquals(
|
|
||||||
GpxTrackWriter.ELEVATION_FORMATTER.format(loc.getAltitude()),
|
|
||||||
getChildTextValue(tag, "ele"));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user