Changeset 14317 in josm for trunk/test/unit/org


Ignore:
Timestamp:
2018-10-13T01:45:52+02:00 (6 years ago)
Author:
Don-vip
Message:

fix #16835 - PluginHandlerTest: fix for non-headless mode by properly mocking dialogs (patch by ris)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/plugins/PluginHandlerTest.java

    r14153 r14317  
    1111import java.util.List;
    1212
     13import javax.swing.JScrollPane;
     14
    1315import org.junit.Rule;
    1416import org.junit.Test;
     
    1618import org.openstreetmap.josm.gui.MainApplication;
    1719import org.openstreetmap.josm.gui.preferences.plugin.PluginPreferenceTest;
     20import org.openstreetmap.josm.gui.widgets.JosmTextArea;
    1821import org.openstreetmap.josm.plugins.PluginHandler.DeprecatedPlugin;
    1922import org.openstreetmap.josm.plugins.PluginHandler.PluginInformationAction;
    2023import org.openstreetmap.josm.testutils.JOSMTestRules;
     24import org.openstreetmap.josm.testutils.mockers.HelpAwareOptionPaneMocker;
     25import org.openstreetmap.josm.testutils.mockers.JOptionPaneSimpleMocker;
    2126import org.openstreetmap.josm.tools.Utils;
     27
     28import com.google.common.collect.ImmutableMap;
    2229
    2330import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
     
    5057    @Test
    5158    public void testBuildListOfPluginsToLoad() {
     59        TestUtils.assumeWorkingJMockit();
     60        final HelpAwareOptionPaneMocker haMocker = new HelpAwareOptionPaneMocker() {
     61            @Override
     62            public String getStringFromMessage(final Object message) {
     63                return ((String) message).substring(0, 66);
     64            }
     65        };
     66        haMocker.getMockResultMap().put(
     67            "<html>JOSM could not find information about the following plugins:",
     68            "OK"
     69        );
    5270        final String old = System.getProperty("josm.plugins");
    5371        try {
     
    6583            }
    6684        }
     85
     86        assertEquals(1, haMocker.getInvocationLog().size());
     87        Object[] invocationLogEntry = haMocker.getInvocationLog().get(0);
     88        assertEquals(0, (int) invocationLogEntry[0]);
     89        assertEquals("Warning", invocationLogEntry[2]);
    6790    }
    6891
     
    7295    @Test
    7396    public void testFilterDeprecatedPlugins() {
     97        TestUtils.assumeWorkingJMockit();
     98        final JOptionPaneSimpleMocker jopsMocker = new JOptionPaneSimpleMocker(
     99            ImmutableMap.<String, Object>of(
     100                "<html>The following plugin is no longer necessary and has been deactivated:" +
     101                    "<ul><li>imagery (integrated into main program)</li></ul></html>",
     102                0
     103            )
     104        );
     105
    74106        List<String> plugins = new ArrayList<>(Arrays.asList("foo", "bar", "imagery"));
    75107        PluginHandler.filterDeprecatedPlugins(MainApplication.getMainFrame(), plugins);
    76108        assertEquals(2, plugins.size());
    77109        assertFalse(plugins.contains("imagery"));
     110
     111        assertEquals(1, jopsMocker.getInvocationLog().size());
     112        Object[] invocationLogEntry = jopsMocker.getInvocationLog().get(0);
     113        assertEquals(0, (int) invocationLogEntry[0]);
     114        assertEquals("Warning", invocationLogEntry[2]);
    78115    }
    79116
     
    83120    @Test
    84121    public void testFilterUnmaintainedPlugins() {
     122        TestUtils.assumeWorkingJMockit();
     123        final HelpAwareOptionPaneMocker haMocker = new HelpAwareOptionPaneMocker(
     124            ImmutableMap.<String, Object>of(
     125                "<html>Loading of the plugin \"gpsbabelgui\" was requested.<br>" +
     126                    "This plugin is no longer developed and very likely will produce errors.<br>" +
     127                    "It should be disabled.<br>Delete from preferences?</html>",
     128                "Disable plugin"
     129            )
     130        );
     131
    85132        List<String> plugins = new ArrayList<>(Arrays.asList("foo", "bar", "gpsbabelgui"));
    86133        PluginHandler.filterUnmaintainedPlugins(MainApplication.getMainFrame(), plugins);
    87134        assertEquals(2, plugins.size());
    88135        assertFalse(plugins.contains("gpsbabelgui"));
     136
     137        assertEquals(1, haMocker.getInvocationLog().size());
     138        Object[] invocationLogEntry = haMocker.getInvocationLog().get(0);
     139        assertEquals(0, (int) invocationLogEntry[0]);
     140        assertEquals("Disable plugin", invocationLogEntry[2]);
    89141    }
    90142
     
    95147    @Test
    96148    public void testPluginInformationAction() throws PluginException {
     149        TestUtils.assumeWorkingJMockit();
     150        final String expectedText = "Ant-Version: Apache Ant 1.9.6\n" +
     151            "Author: Don-vip\n" +
     152            "Created-By: 1.7.0_91-b02 (Oracle Corporation)\n" +
     153            "Manifest-Version: 1.0\n" +
     154            "Plugin-Canloadatruntime: true\n" +
     155            "Plugin-Class: org.openstreetmap.josm.plugins.fr.epci.EpciPlugin\n" +
     156            "Plugin-Date: 2015-11-19T08:21:07.645033Z\n" +
     157            "Plugin-Description: Handling of French EPCIs (boundary=local_authority)\n" +
     158            "Plugin-Early: true\n" +
     159            "Plugin-Link: http://wiki.openstreetmap.org/wiki/FR:JOSM/Fr:Plugin/EPCI-fr\n" +
     160            "Plugin-Mainversion: 7001\n" +
     161            "Plugin-Version: 31772\n";
     162        final JOptionPaneSimpleMocker jopsMocker = new JOptionPaneSimpleMocker() {
     163            @Override
     164            public String getStringFromMessage(final Object message) {
     165                return ((JosmTextArea) ((JScrollPane) message).getViewport().getView()).getText();
     166            }
     167        };
     168        jopsMocker.getMockResultMap().put(expectedText, 0);
     169
    97170        PluginInformationAction action = new PluginInformationAction(PluginPreferenceTest.getDummyPluginInformation());
    98         assertEquals(
    99                 "Ant-Version: Apache Ant 1.9.6\n" +
    100                 "Author: Don-vip\n" +
    101                 "Created-By: 1.7.0_91-b02 (Oracle Corporation)\n" +
    102                 "Manifest-Version: 1.0\n" +
    103                 "Plugin-Canloadatruntime: true\n" +
    104                 "Plugin-Class: org.openstreetmap.josm.plugins.fr.epci.EpciPlugin\n" +
    105                 "Plugin-Date: 2015-11-19T08:21:07.645033Z\n" +
    106                 "Plugin-Description: Handling of French EPCIs (boundary=local_authority)\n" +
    107                 "Plugin-Early: true\n" +
    108                 "Plugin-Link: http://wiki.openstreetmap.org/wiki/FR:JOSM/Fr:Plugin/EPCI-fr\n" +
    109                 "Plugin-Mainversion: 7001\n" +
    110                 "Plugin-Version: 31772\n", action.getText());
     171        assertEquals(expectedText, action.getText());
    111172        action.actionPerformed(null);
     173
     174        assertEquals(1, jopsMocker.getInvocationLog().size());
     175        Object[] invocationLogEntry = jopsMocker.getInvocationLog().get(0);
     176        assertEquals(0, (int) invocationLogEntry[0]);
     177        assertEquals("Plugin information", invocationLogEntry[2]);
    112178    }
    113179}
Note: See TracChangeset for help on using the changeset viewer.