From e57e817a53c2b645b8d2754a33778f1c742cf2bd Mon Sep 17 00:00:00 2001
From: Robert Scott <code@humanleg.org.uk>
Date: Sat, 28 Jul 2018 17:44:24 +0100
Subject: [PATCH v1 2/2] tests: DownloadAlongTrackActionTest: mock out
HelpAwareOptionPane properly
also make sure we assert its result
---
.../layer/gpx/DownloadAlongTrackActionTest.java | 25 +++++++++++++++++++++-
1 file changed, 24 insertions(+), 1 deletion(-)
diff --git a/test/unit/org/openstreetmap/josm/gui/layer/gpx/DownloadAlongTrackActionTest.java b/test/unit/org/openstreetmap/josm/gui/layer/gpx/DownloadAlongTrackActionTest.java
index d850b355a..d62cf7bda 100644
a
|
b
|
|
1 | 1 | // License: GPL. For details, see LICENSE file. |
2 | 2 | package org.openstreetmap.josm.gui.layer.gpx; |
3 | 3 | |
| 4 | import static org.junit.Assert.assertEquals; |
4 | 5 | import static org.junit.Assert.assertNotNull; |
5 | 6 | import static org.junit.Assert.assertNull; |
6 | 7 | |
… |
… |
import org.openstreetmap.josm.gui.PleaseWaitRunnable;
|
14 | 15 | import org.openstreetmap.josm.gui.layer.OsmDataLayer; |
15 | 16 | import org.openstreetmap.josm.io.GpxReaderTest; |
16 | 17 | import org.openstreetmap.josm.testutils.JOSMTestRules; |
| 18 | import org.openstreetmap.josm.testutils.mockers.HelpAwareOptionPaneMocker; |
| 19 | |
| 20 | import com.google.common.collect.ImmutableMap; |
17 | 21 | |
18 | 22 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; |
19 | 23 | |
… |
… |
public class DownloadAlongTrackActionTest {
|
30 | 34 | public JOSMTestRules test = new JOSMTestRules().preferences().platform(); |
31 | 35 | |
32 | 36 | private static PleaseWaitRunnable createTask(String file) throws Exception { |
| 37 | // click "Download" when presented with the appropriate HelpAwareOptionPane |
| 38 | final HelpAwareOptionPaneMocker haMocker = new HelpAwareOptionPaneMocker(ImmutableMap.of( |
| 39 | "DownloadAlongPanel", "Download" |
| 40 | )) { |
| 41 | // expected "message" for HelpAwareOptionPane call is not a simple string, so instead |
| 42 | // just detect the class name of the message object |
| 43 | protected String getStringFromMessage(final Object message) { |
| 44 | return message instanceof String ? (String) message : message.getClass().getSimpleName(); |
| 45 | } |
| 46 | }; |
| 47 | |
33 | 48 | final OsmDataLayer layer = new OsmDataLayer(new DataSet(), DownloadAlongTrackActionTest.class.getName(), null); |
34 | 49 | try { |
35 | 50 | MainApplication.getLayerManager().addLayer(layer); |
36 | 51 | // Perform action |
37 | 52 | final GpxData gpx = GpxReaderTest.parseGpxData(TestUtils.getTestDataRoot() + file); |
38 | | return new DownloadAlongTrackAction(gpx).createTask(); |
| 53 | final PleaseWaitRunnable retval = new DownloadAlongTrackAction(gpx).createTask(); |
| 54 | |
| 55 | // assert that we were indeed presented with the expected HelpAwareOptionPane |
| 56 | assertEquals(1, haMocker.getInvocationLog().size()); |
| 57 | assertEquals(0, haMocker.getInvocationLog().get(0)[0]); |
| 58 | assertEquals("DownloadAlongPanel", haMocker.getInvocationLog().get(0)[1]); |
| 59 | assertEquals("Download from OSM along this track", haMocker.getInvocationLog().get(0)[2]); |
| 60 | |
| 61 | return retval; |
39 | 62 | } finally { |
40 | 63 | // Ensure we clean the place before leaving, even if test fails. |
41 | 64 | MainApplication.getLayerManager().removeLayer(layer); |