From 58ffc119fe9b4f4434c1c375812b7f505004982e Mon Sep 17 00:00:00 2001
From: Robert Scott <code@humanleg.org.uk>
Date: Fri, 26 Oct 2018 23:31:14 +0100
Subject: [PATCH v1] HelpBrowserTest: fix for non-headless mode
---
.../openstreetmap/josm/gui/help/HelpBrowser.java | 14 ++++++--------
.../josm/gui/help/HelpBrowserTest.java | 21 +++++++++++++++++++++
2 files changed, 27 insertions(+), 8 deletions(-)
diff --git a/src/org/openstreetmap/josm/gui/help/HelpBrowser.java b/src/org/openstreetmap/josm/gui/help/HelpBrowser.java
index 1332c2354..db24f2423 100644
|
a
|
b
|
public class HelpBrowser extends JFrame implements IHelpBrowser {
|
| 465 | 465 | url, |
| 466 | 466 | HelpUtil.getWikiBaseUrl() |
| 467 | 467 | ); |
| 468 | | if (!GraphicsEnvironment.isHeadless()) { |
| 469 | | JOptionPane.showMessageDialog( |
| 470 | | MainApplication.getMainFrame(), |
| 471 | | message, |
| 472 | | tr("Warning"), |
| 473 | | JOptionPane.WARNING_MESSAGE |
| 474 | | ); |
| 475 | | } |
| | 468 | JOptionPane.showMessageDialog( |
| | 469 | MainApplication.getMainFrame(), |
| | 470 | message, |
| | 471 | tr("Warning"), |
| | 472 | JOptionPane.WARNING_MESSAGE |
| | 473 | ); |
| 476 | 474 | return; |
| 477 | 475 | } |
| 478 | 476 | url = url.replaceAll("#[^#]*$", ""); |
diff --git a/test/unit/org/openstreetmap/josm/gui/help/HelpBrowserTest.java b/test/unit/org/openstreetmap/josm/gui/help/HelpBrowserTest.java
index f5a7d965e..f4271d519 100644
|
a
|
b
|
package org.openstreetmap.josm.gui.help;
|
| 4 | 4 | import static org.junit.Assert.assertEquals; |
| 5 | 5 | import static org.junit.Assert.assertNull; |
| 6 | 6 | |
| | 7 | import javax.swing.JOptionPane; |
| | 8 | |
| 7 | 9 | import org.junit.Rule; |
| 8 | 10 | import org.junit.Test; |
| | 11 | import org.openstreetmap.josm.TestUtils; |
| 9 | 12 | import org.openstreetmap.josm.testutils.JOSMTestRules; |
| | 13 | import org.openstreetmap.josm.testutils.mockers.JOptionPaneSimpleMocker; |
| 10 | 14 | import org.openstreetmap.josm.tools.LanguageInfo.LocaleType; |
| 11 | 15 | |
| | 16 | import com.google.common.collect.ImmutableMap; |
| | 17 | |
| 12 | 18 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; |
| 13 | 19 | |
| 14 | 20 | /** |
| … |
… |
public class HelpBrowserTest {
|
| 88 | 94 | */ |
| 89 | 95 | @Test |
| 90 | 96 | public void testEditAction() { |
| | 97 | TestUtils.assumeWorkingJMockit(); |
| 91 | 98 | IHelpBrowser browser = newHelpBrowser(); |
| 92 | 99 | assertNull(browser.getUrl()); |
| 93 | 100 | new HelpBrowser.EditAction(browser).actionPerformed(null); |
| … |
… |
public class HelpBrowserTest {
|
| 96 | 103 | assertEquals(URL_2, browser.getUrl()); |
| 97 | 104 | new HelpBrowser.EditAction(browser).actionPerformed(null); |
| 98 | 105 | |
| | 106 | final JOptionPaneSimpleMocker jopsMocker = new JOptionPaneSimpleMocker( |
| | 107 | ImmutableMap.<String, Object>of( |
| | 108 | "<html>The current URL <tt>https://josm.openstreetmap.de/javadoc</tt><br>is an external " |
| | 109 | + "URL. Editing is only possible for help topics<br>on the help server " |
| | 110 | + "<tt>https://josm.openstreetmap.de</tt>.</html>", |
| | 111 | JOptionPane.OK_OPTION |
| | 112 | ) |
| | 113 | ); |
| | 114 | |
| 99 | 115 | browser.openUrl(URL_3); |
| 100 | 116 | assertEquals(URL_3, browser.getUrl()); |
| 101 | 117 | new HelpBrowser.EditAction(browser).actionPerformed(null); |
| | 118 | |
| | 119 | assertEquals(1, jopsMocker.getInvocationLog().size()); |
| | 120 | Object[] invocationLogEntry = jopsMocker.getInvocationLog().get(0); |
| | 121 | assertEquals(JOptionPane.OK_OPTION, (int) invocationLogEntry[0]); |
| | 122 | assertEquals("Warning", invocationLogEntry[2]); |
| 102 | 123 | } |
| 103 | 124 | |
| 104 | 125 | /** |