forked from upstream-mirrors/OpenTracks
Rename TrackFormatWriter to TrackWriter
This commit is contained in:
@@ -21,7 +21,7 @@ package com.google.android.apps.mytracks.io.file;
|
||||
*
|
||||
* @author Rodrigo Damazio
|
||||
*/
|
||||
public class CsvTrackWriterTest extends TrackFormatWriterTest {
|
||||
public class CsvTrackWriterTest extends TrackWriterTest {
|
||||
|
||||
private static final String BEGIN_TAG = "\"";
|
||||
private static final String END_TAG = "\"\n";
|
||||
@@ -62,8 +62,8 @@ public class CsvTrackWriterTest extends TrackFormatWriterTest {
|
||||
+ expectedMarkerHeader + expectedMarker1 + expectedMarker2 + "\n"
|
||||
+ expectedPointHeader + expectedPoint1 + expectedPoint2 + expectedPoint3 + expectedPoint4;
|
||||
|
||||
CsvTrackWriter writer = new CsvTrackWriter(getContext());
|
||||
assertEquals(expected, writeTrack(writer));
|
||||
CsvTrackWriter csvTrackWriter = new CsvTrackWriter(getContext());
|
||||
assertEquals(expected, writeTrack(csvTrackWriter));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -25,11 +25,11 @@ import org.w3c.dom.Element;
|
||||
*
|
||||
* @author Rodrigo Damazio
|
||||
*/
|
||||
public class GpxTrackWriterTest extends TrackFormatWriterTest {
|
||||
public class GpxTrackWriterTest extends TrackWriterTest {
|
||||
|
||||
public void testXmlOutput() throws Exception {
|
||||
TrackFormatWriter writer = new GpxTrackWriter(getContext());
|
||||
String result = writeTrack(writer);
|
||||
GpxTrackWriter gpxTrackWriter = new GpxTrackWriter(getContext());
|
||||
String result = writeTrack(gpxTrackWriter);
|
||||
Document doc = parseXmlDocument(result);
|
||||
|
||||
Element gpxTag = getChildElement(doc, "gpx");
|
||||
|
||||
@@ -32,7 +32,7 @@ import org.w3c.dom.Element;
|
||||
*
|
||||
* @author Rodrigo Damazio
|
||||
*/
|
||||
public class KmlTrackWriterTest extends TrackFormatWriterTest {
|
||||
public class KmlTrackWriterTest extends TrackWriterTest {
|
||||
|
||||
private static final String FULL_TRACK_DESCRIPTION = "full track description";
|
||||
|
||||
@@ -54,8 +54,8 @@ public class KmlTrackWriterTest extends TrackFormatWriterTest {
|
||||
}
|
||||
|
||||
public void testXmlOutput() throws Exception {
|
||||
KmlTrackWriter writer = new KmlTrackWriter(getContext(), new FakeDescriptionGenerator());
|
||||
String result = writeTrack(writer);
|
||||
KmlTrackWriter kmlTrackWriter = new KmlTrackWriter(getContext(), new FakeDescriptionGenerator());
|
||||
String result = writeTrack(kmlTrackWriter);
|
||||
Document doc = parseXmlDocument(result);
|
||||
|
||||
Element kmlTag = getChildElement(doc, "kml");
|
||||
|
||||
@@ -29,11 +29,11 @@ import org.w3c.dom.Element;
|
||||
*
|
||||
* @author Sandor Dornbush
|
||||
*/
|
||||
public class TcxTrackWriterTest extends TrackFormatWriterTest {
|
||||
public class TcxTrackWriterTest extends TrackWriterTest {
|
||||
|
||||
public void testXmlOutput() throws Exception {
|
||||
TrackFormatWriter writer = new TcxTrackWriter(getContext());
|
||||
String result = writeTrack(writer);
|
||||
TcxTrackWriter tcxTrackWriter = new TcxTrackWriter(getContext());
|
||||
String result = writeTrack(tcxTrackWriter);
|
||||
Document doc = parseXmlDocument(result);
|
||||
|
||||
Element root = getChildElement(doc, "TrainingCenterDatabase");
|
||||
|
||||
@@ -39,7 +39,7 @@ public class TrackExporterTest extends AndroidTestCase {
|
||||
|
||||
private IMocksControl mocksControl;
|
||||
|
||||
private TrackFormatWriter trackFormatWriter;
|
||||
private TrackWriter trackWriter;
|
||||
private Track track;
|
||||
private OutputStream outputStream;
|
||||
private TrackExporter trackExporter;
|
||||
@@ -61,7 +61,7 @@ public class TrackExporterTest extends AndroidTestCase {
|
||||
myTracksProviderUtils);
|
||||
|
||||
mocksControl = EasyMock.createStrictControl();
|
||||
trackFormatWriter = mocksControl.createMock(TrackFormatWriter.class);
|
||||
trackWriter = mocksControl.createMock(TrackWriter.class);
|
||||
|
||||
track = new Track();
|
||||
track.setName(TRACK_NAME);
|
||||
@@ -76,7 +76,7 @@ public class TrackExporterTest extends AndroidTestCase {
|
||||
|
||||
}
|
||||
};
|
||||
trackExporter = new TrackExporter(myTracksProviderUtils, new Track[] {track}, trackFormatWriter, onWriteListener);
|
||||
trackExporter = new TrackExporter(myTracksProviderUtils, new Track[] {track}, trackWriter, onWriteListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -91,12 +91,12 @@ public class TrackExporterTest extends AndroidTestCase {
|
||||
public void testWriteTrack_emptyTrack() throws Exception {
|
||||
|
||||
// Set expected mock behavior
|
||||
trackFormatWriter.prepare(outputStream);
|
||||
trackFormatWriter.writeHeader(track);
|
||||
trackFormatWriter.writeBeginTrack(track, null);
|
||||
trackFormatWriter.writeEndTrack(track, null);
|
||||
trackFormatWriter.writeFooter();
|
||||
trackFormatWriter.close();
|
||||
trackWriter.prepare(outputStream);
|
||||
trackWriter.writeHeader(track);
|
||||
trackWriter.writeBeginTrack(track, null);
|
||||
trackWriter.writeEndTrack(track, null);
|
||||
trackWriter.writeFooter();
|
||||
trackWriter.close();
|
||||
|
||||
mocksControl.replay();
|
||||
trackExporter.writeTrack(outputStream);
|
||||
@@ -123,12 +123,12 @@ public class TrackExporterTest extends AndroidTestCase {
|
||||
myTracksProviderUtils.bulkInsertTrackPoint(locations, locations.length, TRACK_ID));
|
||||
|
||||
// Set expected mock behavior
|
||||
trackFormatWriter.prepare(outputStream);
|
||||
trackFormatWriter.writeHeader(track);
|
||||
trackFormatWriter.writeBeginTrack(track, null);
|
||||
trackFormatWriter.writeEndTrack(track, null);
|
||||
trackFormatWriter.writeFooter();
|
||||
trackFormatWriter.close();
|
||||
trackWriter.prepare(outputStream);
|
||||
trackWriter.writeHeader(track);
|
||||
trackWriter.writeBeginTrack(track, null);
|
||||
trackWriter.writeEndTrack(track, null);
|
||||
trackWriter.writeFooter();
|
||||
trackWriter.close();
|
||||
|
||||
mocksControl.replay();
|
||||
trackExporter.writeTrack(outputStream);
|
||||
@@ -162,38 +162,38 @@ public class TrackExporterTest extends AndroidTestCase {
|
||||
waypoint.setId(i + 1);
|
||||
}
|
||||
|
||||
trackFormatWriter.prepare(outputStream);
|
||||
trackFormatWriter.writeHeader(track);
|
||||
trackWriter.prepare(outputStream);
|
||||
trackWriter.writeHeader(track);
|
||||
|
||||
// Expect reading/writing of the waypoints (except the first)
|
||||
trackFormatWriter.writeBeginWaypoints();
|
||||
trackFormatWriter.writeWaypoint(waypointEq(waypoints[1]));
|
||||
trackFormatWriter.writeWaypoint(waypointEq(waypoints[2]));
|
||||
trackFormatWriter.writeEndWaypoints();
|
||||
trackWriter.writeBeginWaypoints();
|
||||
trackWriter.writeWaypoint(waypointEq(waypoints[1]));
|
||||
trackWriter.writeWaypoint(waypointEq(waypoints[2]));
|
||||
trackWriter.writeEndWaypoints();
|
||||
|
||||
// Begin the track
|
||||
trackFormatWriter.writeBeginTrack(trackEq(track), locationEq(locations[0]));
|
||||
trackWriter.writeBeginTrack(trackEq(track), locationEq(locations[0]));
|
||||
|
||||
// Write locations 1-2
|
||||
trackFormatWriter.writeOpenSegment();
|
||||
trackFormatWriter.writeLocation(locationEq(locations[0]));
|
||||
trackFormatWriter.writeLocation(locationEq(locations[1]));
|
||||
trackFormatWriter.writeCloseSegment();
|
||||
trackWriter.writeOpenSegment();
|
||||
trackWriter.writeLocation(locationEq(locations[0]));
|
||||
trackWriter.writeLocation(locationEq(locations[1]));
|
||||
trackWriter.writeCloseSegment();
|
||||
|
||||
// Location 3 is not written - it's invalid
|
||||
|
||||
// Write locations 4-6
|
||||
trackFormatWriter.writeOpenSegment();
|
||||
trackFormatWriter.writeLocation(locationEq(locations[3]));
|
||||
trackFormatWriter.writeLocation(locationEq(locations[4]));
|
||||
trackFormatWriter.writeLocation(locationEq(locations[5]));
|
||||
trackFormatWriter.writeCloseSegment();
|
||||
trackWriter.writeOpenSegment();
|
||||
trackWriter.writeLocation(locationEq(locations[3]));
|
||||
trackWriter.writeLocation(locationEq(locations[4]));
|
||||
trackWriter.writeLocation(locationEq(locations[5]));
|
||||
trackWriter.writeCloseSegment();
|
||||
|
||||
// End the track
|
||||
trackFormatWriter.writeEndTrack(trackEq(track), locationEq(locations[5]));
|
||||
trackWriter.writeEndTrack(trackEq(track), locationEq(locations[5]));
|
||||
|
||||
trackFormatWriter.writeFooter();
|
||||
trackFormatWriter.close();
|
||||
trackWriter.writeFooter();
|
||||
trackWriter.close();
|
||||
|
||||
mocksControl.replay();
|
||||
trackExporter.writeTrack(outputStream);
|
||||
|
||||
+21
-21
@@ -34,7 +34,7 @@ import org.xml.sax.SAXException;
|
||||
*
|
||||
* @author Rodrigo Damazio
|
||||
*/
|
||||
public abstract class TrackFormatWriterTest extends AndroidTestCase {
|
||||
public abstract class TrackWriterTest extends AndroidTestCase {
|
||||
|
||||
// All the user-provided strings have "]]>" to ensure that proper escaping is
|
||||
// being done.
|
||||
@@ -110,29 +110,29 @@ public abstract class TrackFormatWriterTest extends AndroidTestCase {
|
||||
* Makes the right sequence of calls to the writer in order to write the fake
|
||||
* track in {@link #track}.
|
||||
*
|
||||
* @param writer the writer to write to
|
||||
* @param trackWriter the track writer
|
||||
* @return the written contents
|
||||
*/
|
||||
protected String writeTrack(TrackFormatWriter writer) throws Exception {
|
||||
protected String writeTrack(TrackWriter trackWriter) throws Exception {
|
||||
OutputStream output = new ByteArrayOutputStream(BUFFER_SIZE);
|
||||
writer.prepare(output);
|
||||
writer.writeHeader(track);
|
||||
writer.writeBeginWaypoints();
|
||||
writer.writeWaypoint(wp1);
|
||||
writer.writeWaypoint(wp2);
|
||||
writer.writeEndWaypoints();
|
||||
writer.writeBeginTrack(track, location1);
|
||||
writer.writeOpenSegment();
|
||||
writer.writeLocation(location1);
|
||||
writer.writeLocation(location2);
|
||||
writer.writeCloseSegment();
|
||||
writer.writeOpenSegment();
|
||||
writer.writeLocation(location3);
|
||||
writer.writeLocation(location4);
|
||||
writer.writeCloseSegment();
|
||||
writer.writeEndTrack(track, location4);
|
||||
writer.writeFooter();
|
||||
writer.close();
|
||||
trackWriter.prepare(output);
|
||||
trackWriter.writeHeader(track);
|
||||
trackWriter.writeBeginWaypoints();
|
||||
trackWriter.writeWaypoint(wp1);
|
||||
trackWriter.writeWaypoint(wp2);
|
||||
trackWriter.writeEndWaypoints();
|
||||
trackWriter.writeBeginTrack(track, location1);
|
||||
trackWriter.writeOpenSegment();
|
||||
trackWriter.writeLocation(location1);
|
||||
trackWriter.writeLocation(location2);
|
||||
trackWriter.writeCloseSegment();
|
||||
trackWriter.writeOpenSegment();
|
||||
trackWriter.writeLocation(location3);
|
||||
trackWriter.writeLocation(location4);
|
||||
trackWriter.writeCloseSegment();
|
||||
trackWriter.writeEndTrack(track, location4);
|
||||
trackWriter.writeFooter();
|
||||
trackWriter.close();
|
||||
return output.toString();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user