source: josm/trunk/test/unit/org/openstreetmap/josm/gui/layer/gpx/DownloadAlongTrackActionTest.java

Last change on this file was 18037, checked in by Don-vip, 3 years ago

fix #21064 - Add JUnit 5 extension for preferences (patch by taylor.smock)

  • Property svn:eol-style set to native
File size: 3.1 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.layer.gpx;
3
4import static org.junit.jupiter.api.Assertions.assertEquals;
5import static org.junit.jupiter.api.Assertions.assertNotNull;
6import static org.junit.jupiter.api.Assertions.assertNull;
7
8import java.util.Collections;
9
10import org.junit.jupiter.api.Test;
11import org.openstreetmap.josm.TestUtils;
12import org.openstreetmap.josm.data.gpx.GpxData;
13import org.openstreetmap.josm.data.osm.DataSet;
14import org.openstreetmap.josm.gui.MainApplication;
15import org.openstreetmap.josm.gui.PleaseWaitRunnable;
16import org.openstreetmap.josm.gui.layer.OsmDataLayer;
17import org.openstreetmap.josm.io.GpxReaderTest;
18import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
19import org.openstreetmap.josm.testutils.mockers.HelpAwareOptionPaneMocker;
20
21/**
22 * Unit tests of {@link DownloadAlongTrackAction} class.
23 */
24@BasicPreferences
25class 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}
Note: See TracBrowser for help on using the repository browser.