Ticket #16010: v1-0002-tests-DownloadAlongTrackActionTest-mock-out-HelpA.patch

File v1-0002-tests-DownloadAlongTrackActionTest-mock-out-HelpA.patch, 3.4 KB (added by ris, 3 years ago)
  • test/unit/org/openstreetmap/josm/gui/layer/gpx/DownloadAlongTrackActionTest.java

    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  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.gui.layer.gpx;
    33
     4import static org.junit.Assert.assertEquals;
    45import static org.junit.Assert.assertNotNull;
    56import static org.junit.Assert.assertNull;
    67
    import org.openstreetmap.josm.gui.PleaseWaitRunnable; 
    1415import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    1516import org.openstreetmap.josm.io.GpxReaderTest;
    1617import org.openstreetmap.josm.testutils.JOSMTestRules;
     18import org.openstreetmap.josm.testutils.mockers.HelpAwareOptionPaneMocker;
     19
     20import com.google.common.collect.ImmutableMap;
    1721
    1822import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    1923
    public class DownloadAlongTrackActionTest { 
    3034    public JOSMTestRules test = new JOSMTestRules().preferences().platform();
    3135
    3236    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
    3348        final OsmDataLayer layer = new OsmDataLayer(new DataSet(), DownloadAlongTrackActionTest.class.getName(), null);
    3449        try {
    3550            MainApplication.getLayerManager().addLayer(layer);
    3651            // Perform action
    3752            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;
    3962        } finally {
    4063            // Ensure we clean the place before leaving, even if test fails.
    4164            MainApplication.getLayerManager().removeLayer(layer);