Ticket #16954: v1-0001-MainApplicationTest-fix-for-non-headless-mode.patch

File v1-0001-MainApplicationTest-fix-for-non-headless-mode.patch, 6.1 KB (added by ris, 8 years ago)
  • src/org/openstreetmap/josm/gui/DownloadParamType.java

    From ae93084a4079589326fed696ca2782b8793c3d42 Mon Sep 17 00:00:00 2001
    From: Robert Scott <code@humanleg.org.uk>
    Date: Sun, 4 Nov 2018 23:10:56 +0000
    Subject: [PATCH v1] MainApplicationTest: fix for non-headless mode
    
    ---
     .../openstreetmap/josm/gui/DownloadParamType.java  | 14 +++----
     .../josm/gui/MainApplicationTest.java              | 48 ++++++++++++++++++++++
     2 files changed, 54 insertions(+), 8 deletions(-)
    
    diff --git a/src/org/openstreetmap/josm/gui/DownloadParamType.java b/src/org/openstreetmap/josm/gui/DownloadParamType.java
    index 2cf2b3bab..81e7e98e9 100644
    a b public enum DownloadParamType {  
    123123     * @return the download task, or {@code null}
    124124     */
    125125    public List<Future<?>> downloadGps(String param) {
    126         if (!GraphicsEnvironment.isHeadless()) {
    127             JOptionPane.showMessageDialog(
    128                     MainApplication.getMainFrame(),
    129                     tr("Parameter \"downloadgps\" does not accept file names or file URLs"),
    130                     tr("Warning"),
    131                     JOptionPane.WARNING_MESSAGE
    132             );
    133         }
     126        JOptionPane.showMessageDialog(
     127                MainApplication.getMainFrame(),
     128                tr("Parameter \"downloadgps\" does not accept file names or file URLs"),
     129                tr("Warning"),
     130                JOptionPane.WARNING_MESSAGE
     131        );
    134132        return Collections.emptyList();
    135133    }
    136134
  • test/unit/org/openstreetmap/josm/gui/MainApplicationTest.java

    diff --git a/test/unit/org/openstreetmap/josm/gui/MainApplicationTest.java b/test/unit/org/openstreetmap/josm/gui/MainApplicationTest.java
    index e30ac0bab..eff556252 100644
    a b import java.util.List;  
    2222import java.util.concurrent.ExecutionException;
    2323import java.util.concurrent.Future;
    2424
     25import java.awt.GraphicsEnvironment;
    2526import javax.swing.JComponent;
     27import javax.swing.JOptionPane;
    2628import javax.swing.JPanel;
    2729import javax.swing.UIManager;
    2830
    import org.openstreetmap.josm.plugins.PluginListParseException;  
    4345import org.openstreetmap.josm.plugins.PluginListParser;
    4446import org.openstreetmap.josm.spi.preferences.Config;
    4547import org.openstreetmap.josm.testutils.JOSMTestRules;
     48import org.openstreetmap.josm.testutils.mockers.HelpAwareOptionPaneMocker;
     49import org.openstreetmap.josm.testutils.mockers.JOptionPaneSimpleMocker;
    4650import org.openstreetmap.josm.tools.Logging;
    4751import org.openstreetmap.josm.tools.PlatformManager;
    4852import org.openstreetmap.josm.tools.Shortcut;
    4953
     54import com.google.common.collect.ImmutableMap;
     55
    5056import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    5157
    5258/**
    public class MainApplicationTest {  
    164170     */
    165171    @Test
    166172    public void testUpdateAndLoadPlugins() throws PluginListParseException {
     173        TestUtils.assumeWorkingJMockit();
     174        final HelpAwareOptionPaneMocker haMocker = new HelpAwareOptionPaneMocker(
     175            ImmutableMap.<String, Object>of(
     176                "<html>JOSM could not find information about the following plugins:<ul>"
     177                + "<li>buildings_tools</li><li>plastic_laf</li></ul>The plugins are not "
     178                + "going to be loaded.</html>",
     179                "OK"
     180            )
     181        );
     182
    167183        final String old = System.getProperty("josm.plugins");
    168184        try {
    169185            System.setProperty("josm.plugins", "buildings_tools,plastic_laf");
    public class MainApplicationTest {  
    189205                System.clearProperty("josm.plugins");
    190206            }
    191207        }
     208
     209        // TODO remove following headless check once similar check removed from HelpAwareOptionPane
     210        if (!GraphicsEnvironment.isHeadless()) {
     211            assertEquals(1, haMocker.getInvocationLog().size());
     212            Object[] invocationLogEntry = haMocker.getInvocationLog().get(0);
     213            assertEquals(0, (int) invocationLogEntry[0]);
     214            assertEquals("Warning", invocationLogEntry[2]);
     215        }
    192216    }
    193217
    194218    /**
    public class MainApplicationTest {  
    267291     */
    268292    @Test
    269293    public void testPostConstructorProcessCmdLineFileUrl() throws MalformedURLException {
     294        TestUtils.assumeWorkingJMockit();
     295        final JOptionPaneSimpleMocker jopsMocker = new JOptionPaneSimpleMocker(
     296            ImmutableMap.<String, Object>of(
     297                "Parameter \"downloadgps\" does not accept file names or file URLs", JOptionPane.OK_OPTION
     298            )
     299        );
     300
    270301        doTestPostConstructorProcessCmdLine(
    271302                Paths.get(TestUtils.getTestDataRoot() + "multipolygon.osm").toUri().toURL().toExternalForm(),
    272303                Paths.get(TestUtils.getTestDataRoot() + "minimal.gpx").toUri().toURL().toExternalForm(), false);
     304
     305        assertEquals(1, jopsMocker.getInvocationLog().size());
     306        Object[] invocationLogEntry = jopsMocker.getInvocationLog().get(0);
     307        assertEquals(JOptionPane.OK_OPTION, (int) invocationLogEntry[0]);
     308        assertEquals("Warning", invocationLogEntry[2]);
    273309    }
    274310
    275311    /**
    public class MainApplicationTest {  
    278314     */
    279315    @Test
    280316    public void testPostConstructorProcessCmdLineFilename() throws MalformedURLException {
     317        TestUtils.assumeWorkingJMockit();
     318        final JOptionPaneSimpleMocker jopsMocker = new JOptionPaneSimpleMocker(
     319            ImmutableMap.<String, Object>of(
     320                "Parameter \"downloadgps\" does not accept file names or file URLs", JOptionPane.OK_OPTION
     321            )
     322        );
     323
    281324        doTestPostConstructorProcessCmdLine(
    282325                Paths.get(TestUtils.getTestDataRoot() + "multipolygon.osm").toFile().getAbsolutePath(),
    283326                Paths.get(TestUtils.getTestDataRoot() + "minimal.gpx").toFile().getAbsolutePath(), false);
     327
     328        assertEquals(1, jopsMocker.getInvocationLog().size());
     329        Object[] invocationLogEntry = jopsMocker.getInvocationLog().get(0);
     330        assertEquals(JOptionPane.OK_OPTION, (int) invocationLogEntry[0]);
     331        assertEquals("Warning", invocationLogEntry[2]);
    284332    }
    285333
    286334    /**