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 {
|
| 123 | 123 | * @return the download task, or {@code null} |
| 124 | 124 | */ |
| 125 | 125 | 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 | ); |
| 134 | 132 | return Collections.emptyList(); |
| 135 | 133 | } |
| 136 | 134 | |
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;
|
| 22 | 22 | import java.util.concurrent.ExecutionException; |
| 23 | 23 | import java.util.concurrent.Future; |
| 24 | 24 | |
| | 25 | import java.awt.GraphicsEnvironment; |
| 25 | 26 | import javax.swing.JComponent; |
| | 27 | import javax.swing.JOptionPane; |
| 26 | 28 | import javax.swing.JPanel; |
| 27 | 29 | import javax.swing.UIManager; |
| 28 | 30 | |
| … |
… |
import org.openstreetmap.josm.plugins.PluginListParseException;
|
| 43 | 45 | import org.openstreetmap.josm.plugins.PluginListParser; |
| 44 | 46 | import org.openstreetmap.josm.spi.preferences.Config; |
| 45 | 47 | import org.openstreetmap.josm.testutils.JOSMTestRules; |
| | 48 | import org.openstreetmap.josm.testutils.mockers.HelpAwareOptionPaneMocker; |
| | 49 | import org.openstreetmap.josm.testutils.mockers.JOptionPaneSimpleMocker; |
| 46 | 50 | import org.openstreetmap.josm.tools.Logging; |
| 47 | 51 | import org.openstreetmap.josm.tools.PlatformManager; |
| 48 | 52 | import org.openstreetmap.josm.tools.Shortcut; |
| 49 | 53 | |
| | 54 | import com.google.common.collect.ImmutableMap; |
| | 55 | |
| 50 | 56 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; |
| 51 | 57 | |
| 52 | 58 | /** |
| … |
… |
public class MainApplicationTest {
|
| 164 | 170 | */ |
| 165 | 171 | @Test |
| 166 | 172 | 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 | |
| 167 | 183 | final String old = System.getProperty("josm.plugins"); |
| 168 | 184 | try { |
| 169 | 185 | System.setProperty("josm.plugins", "buildings_tools,plastic_laf"); |
| … |
… |
public class MainApplicationTest {
|
| 189 | 205 | System.clearProperty("josm.plugins"); |
| 190 | 206 | } |
| 191 | 207 | } |
| | 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 | } |
| 192 | 216 | } |
| 193 | 217 | |
| 194 | 218 | /** |
| … |
… |
public class MainApplicationTest {
|
| 267 | 291 | */ |
| 268 | 292 | @Test |
| 269 | 293 | 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 | |
| 270 | 301 | doTestPostConstructorProcessCmdLine( |
| 271 | 302 | Paths.get(TestUtils.getTestDataRoot() + "multipolygon.osm").toUri().toURL().toExternalForm(), |
| 272 | 303 | 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]); |
| 273 | 309 | } |
| 274 | 310 | |
| 275 | 311 | /** |
| … |
… |
public class MainApplicationTest {
|
| 278 | 314 | */ |
| 279 | 315 | @Test |
| 280 | 316 | 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 | |
| 281 | 324 | doTestPostConstructorProcessCmdLine( |
| 282 | 325 | Paths.get(TestUtils.getTestDataRoot() + "multipolygon.osm").toFile().getAbsolutePath(), |
| 283 | 326 | 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]); |
| 284 | 332 | } |
| 285 | 333 | |
| 286 | 334 | /** |