1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.layer.gpx;
|
---|
3 |
|
---|
4 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
---|
5 | import static org.junit.jupiter.api.Assertions.assertNotNull;
|
---|
6 | import static org.junit.jupiter.api.Assertions.assertNull;
|
---|
7 |
|
---|
8 | import java.util.Collections;
|
---|
9 |
|
---|
10 | import org.junit.jupiter.api.Test;
|
---|
11 | import org.openstreetmap.josm.TestUtils;
|
---|
12 | import org.openstreetmap.josm.data.gpx.GpxData;
|
---|
13 | import org.openstreetmap.josm.data.osm.DataSet;
|
---|
14 | import org.openstreetmap.josm.gui.MainApplication;
|
---|
15 | import org.openstreetmap.josm.gui.PleaseWaitRunnable;
|
---|
16 | import org.openstreetmap.josm.gui.layer.OsmDataLayer;
|
---|
17 | import org.openstreetmap.josm.io.GpxReaderTest;
|
---|
18 | import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
|
---|
19 | import org.openstreetmap.josm.testutils.mockers.HelpAwareOptionPaneMocker;
|
---|
20 |
|
---|
21 | /**
|
---|
22 | * Unit tests of {@link DownloadAlongTrackAction} class.
|
---|
23 | */
|
---|
24 | @BasicPreferences
|
---|
25 | class DownloadAlongTrackActionTest {
|
---|
26 | private static PleaseWaitRunnable createTask(String file) throws Exception {
|
---|
27 | // click "Download" when presented with the appropriate HelpAwareOptionPane
|
---|
28 | final HelpAwareOptionPaneMocker haMocker = new HelpAwareOptionPaneMocker(Collections.singletonMap(
|
---|
29 | "DownloadAlongPanel", "Download"
|
---|
30 | )) {
|
---|
31 | // expected "message" for HelpAwareOptionPane call is not a simple string, so instead
|
---|
32 | // just detect the class name of the message object
|
---|
33 | @Override
|
---|
34 | protected String getStringFromMessage(final Object message) {
|
---|
35 | return message instanceof String ? (String) message : message.getClass().getSimpleName();
|
---|
36 | }
|
---|
37 | };
|
---|
38 |
|
---|
39 | final OsmDataLayer layer = new OsmDataLayer(new DataSet(), DownloadAlongTrackActionTest.class.getName(), null);
|
---|
40 | try {
|
---|
41 | MainApplication.getLayerManager().addLayer(layer);
|
---|
42 | // Perform action
|
---|
43 | final GpxData gpx = GpxReaderTest.parseGpxData(TestUtils.getTestDataRoot() + file);
|
---|
44 | final PleaseWaitRunnable retval = new DownloadAlongTrackAction(Collections.singleton(gpx)).createTask();
|
---|
45 |
|
---|
46 | // assert that we were indeed presented with the expected HelpAwareOptionPane
|
---|
47 | assertEquals(1, haMocker.getInvocationLog().size());
|
---|
48 | assertEquals(0, haMocker.getInvocationLog().get(0)[0]);
|
---|
49 | assertEquals("DownloadAlongPanel", haMocker.getInvocationLog().get(0)[1]);
|
---|
50 | assertEquals("Download from OSM along this track", haMocker.getInvocationLog().get(0)[2]);
|
---|
51 |
|
---|
52 | return retval;
|
---|
53 | } finally {
|
---|
54 | // Ensure we clean the place before leaving, even if test fails.
|
---|
55 | MainApplication.getLayerManager().removeLayer(layer);
|
---|
56 | }
|
---|
57 | }
|
---|
58 |
|
---|
59 | /**
|
---|
60 | * Test action with nominal data set.
|
---|
61 | * @throws Exception if an error occurs
|
---|
62 | */
|
---|
63 | @Test
|
---|
64 | void testDownload() throws Exception {
|
---|
65 | assertNotNull(createTask("minimal.gpx"));
|
---|
66 | }
|
---|
67 |
|
---|
68 | /**
|
---|
69 | * Test action with empty data set.
|
---|
70 | * @throws Exception if an error occurs
|
---|
71 | */
|
---|
72 | @Test
|
---|
73 | void testDownloadEmpty() throws Exception {
|
---|
74 | assertNull(createTask("empty.gpx"));
|
---|
75 | }
|
---|
76 | }
|
---|