Changeset 8908 in josm


Ignore:
Timestamp:
2015-10-19T16:55:23+02:00 (9 years ago)
Author:
Don-vip
Message:

improve download tasks unit tests

Location:
trunk
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/AbstractDownloadTask.java

    r8840 r8908  
    99/**
    1010 * Common abstract implementation of other download tasks
     11 * @param <T> The downloaded data type
    1112 * @since 2322
    1213 */
    13 public abstract class AbstractDownloadTask implements DownloadTask {
     14public abstract class AbstractDownloadTask<T> implements DownloadTask {
    1415    private List<Object> errorMessages;
    1516    private boolean canceled;
    1617    private boolean failed;
     18    protected T downloadedData;
    1719
    1820    public AbstractDownloadTask() {
     
    3638    }
    3739
    38     protected void rememberErrorMessage(String message) {
     40    protected final void rememberErrorMessage(String message) {
    3941        errorMessages.add(message);
    4042    }
    4143
    42     protected void rememberException(Exception exception) {
     44    protected final void rememberException(Exception exception) {
    4345        errorMessages.add(exception);
     46    }
     47
     48    protected final void rememberDownloadedData(T data) {
     49        this.downloadedData = data;
     50    }
     51
     52    /**
     53     * Replies the downloaded data.
     54     * @return The downloaded data.
     55     */
     56    public final T getDownloadedData() {
     57        return downloadedData;
    4458    }
    4559
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadGpsTask.java

    r8904 r8908  
    3333 * Task allowing to download GPS data.
    3434 */
    35 public class DownloadGpsTask extends AbstractDownloadTask {
     35public class DownloadGpsTask extends AbstractDownloadTask<GpxData> {
    3636
    3737    private DownloadTask downloadTask;
     
    128128        @Override
    129129        protected void finish() {
     130            rememberDownloadedData(rawData);
    130131            if (isCanceled() || isFailed())
    131132                return;
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadNotesTask.java

    r8855 r8908  
    1515import org.openstreetmap.josm.data.Bounds;
    1616import org.openstreetmap.josm.data.notes.Note;
     17import org.openstreetmap.josm.data.osm.NoteData;
    1718import org.openstreetmap.josm.data.preferences.IntegerProperty;
    1819import org.openstreetmap.josm.gui.PleaseWaitRunnable;
     
    2728
    2829/** Task for downloading notes */
    29 public class DownloadNotesTask extends AbstractDownloadTask {
     30public class DownloadNotesTask extends AbstractDownloadTask<NoteData> {
    3031
    3132    private static final String PATTERN_API_URL = "https?://.*/api/0.6/notes.*";
     
    3839    private DownloadTask downloadTask;
    3940
     41    /**
     42     * Download a specific note by its id.
     43     * @param id Note identifier
     44     * @param progressMonitor progress monitor
     45     * @return the future representing the asynchronous task
     46     */
    4047    public Future<?> download(long id, ProgressMonitor progressMonitor) {
    4148        final String url = OsmApi.getOsmApi().getBaseUrl() + "notes/" + id;
     
    98105        @Override
    99106        protected void finish() {
     107            rememberDownloadedData(new NoteData(notesData));
    100108            if (isCanceled() || isFailed()) {
    101109                return;
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmTask.java

    r8846 r8908  
    3636 * Run in the worker thread.
    3737 */
    38 public class DownloadOsmTask extends AbstractDownloadTask {
     38public class DownloadOsmTask extends AbstractDownloadTask<DataSet> {
    3939
    4040    protected static final String PATTERN_OSM_API_URL           = "https?://.*/api/0.6/(map|nodes?|ways?|relations?|\\*).*";
     
    4444
    4545    protected Bounds currentBounds;
    46     protected DataSet downloadedData;
    4746    protected DownloadTask downloadTask;
    4847
     
    6665            return super.getTitle();
    6766        }
    68     }
    69 
    70     protected void rememberDownloadedData(DataSet ds) {
    71         this.downloadedData = ds;
    72     }
    73 
    74     /**
    75      * Replies the {@link DataSet} containing the downloaded OSM data.
    76      * @return The {@link DataSet} containing the downloaded OSM data.
    77      */
    78     public DataSet getDownloadedData() {
    79         return downloadedData;
    8067    }
    8168
  • trunk/test/unit/org/openstreetmap/josm/actions/downloadtasks/DownloadGpsTaskTest.java

    r8904 r8908  
    33
    44import static org.junit.Assert.assertFalse;
     5import static org.junit.Assert.assertNotNull;
    56import static org.junit.Assert.assertTrue;
    67
     
    1011import org.junit.Test;
    1112import org.openstreetmap.josm.JOSMFixture;
     13import org.openstreetmap.josm.data.gpx.GpxData;
    1214
    1315/**
     
    5153        DownloadGpsTask task = new DownloadGpsTask();
    5254        task.loadUrl(false, REMOTE_FILE, null).get();
     55        GpxData data = task.getDownloadedData();
     56        assertNotNull(data);
     57        assertFalse(data.waypoints.isEmpty());
     58        assertFalse(data.tracks.isEmpty());
    5359    }
    5460}
  • trunk/test/unit/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmTaskTest.java

    r8904 r8908  
    33
    44import static org.junit.Assert.assertFalse;
     5import static org.junit.Assert.assertNotNull;
    56import static org.junit.Assert.assertTrue;
    67
     
    1011import org.junit.Test;
    1112import org.openstreetmap.josm.JOSMFixture;
     13import org.openstreetmap.josm.data.osm.DataSet;
    1214
    1315/**
     
    5254        DownloadOsmTask task = new DownloadOsmTask();
    5355        task.loadUrl(false, REMOTE_FILE, null).get();
     56        DataSet ds = task.getDownloadedData();
     57        assertNotNull(ds);
     58        assertFalse(ds.getNodes().isEmpty());
     59        assertFalse(ds.getWays().isEmpty());
    5460    }
    5561}
Note: See TracChangeset for help on using the changeset viewer.