Changeset 15737 in josm


Ignore:
Timestamp:
2020-01-20T01:16:42+01:00 (4 years ago)
Author:
Don-vip
Message:

fix #18576 - fix PluginHandlerTest#testBuildListOfPluginsToLoad unit test

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/plugins/PluginHandler.java

    r15686 r15737  
    8989     * Deprecated plugins that are removed on start
    9090     */
    91     static final Collection<DeprecatedPlugin> DEPRECATED_PLUGINS;
     91    static final List<DeprecatedPlugin> DEPRECATED_PLUGINS;
    9292    static {
    9393        String inCore = tr("integrated into main program");
     
    160160            new DeprecatedPlugin("rapid", tr(replacedByPlugin, "MapWithAI"))
    161161        );
     162        Collections.sort(DEPRECATED_PLUGINS);
    162163    }
    163164
     
    368369        // notify user about removed deprecated plugins
    369370        //
     371        JOptionPane.showMessageDialog(
     372                parent,
     373                getRemovedPluginsMessage(removedPlugins),
     374                tr("Warning"),
     375                JOptionPane.WARNING_MESSAGE
     376        );
     377    }
     378
     379    static String getRemovedPluginsMessage(Collection<DeprecatedPlugin> removedPlugins) {
    370380        StringBuilder sb = new StringBuilder(32);
    371381        sb.append("<html>")
     
    383393        }
    384394        sb.append("</ul></html>");
    385         JOptionPane.showMessageDialog(
    386                 parent,
    387                 sb.toString(),
    388                 tr("Warning"),
    389                 JOptionPane.WARNING_MESSAGE
    390         );
     395        return sb.toString();
    391396    }
    392397
     
    406411                continue;
    407412            }
    408             String msg = tr("<html>Loading of the plugin \"{0}\" was requested."
    409                     + "<br>This plugin is no longer developed and very likely will produce errors."
    410                     +"<br>It should be disabled.<br>Delete from preferences?</html>",
    411                     Utils.escapeReservedCharactersHTML(unmaintained));
    412             if (confirmDisablePlugin(parent, msg, unmaintained)) {
     413            if (confirmDisablePlugin(parent, getUnmaintainedPluginMessage(unmaintained), unmaintained)) {
    413414                PreferencesUtils.removeFromList(Config.getPref(), "plugins", unmaintained);
    414415                plugins.remove(unmaintained);
    415416            }
    416417        }
     418    }
     419
     420    static String getUnmaintainedPluginMessage(String unmaintained) {
     421        return tr("<html>Loading of the plugin \"{0}\" was requested."
     422                + "<br>This plugin is no longer developed and very likely will produce errors."
     423                +"<br>It should be disabled.<br>Delete from preferences?</html>",
     424                Utils.escapeReservedCharactersHTML(unmaintained));
    417425    }
    418426
  • trunk/test/unit/org/openstreetmap/josm/plugins/PluginHandlerTest.java

    r15723 r15737  
    1313import java.util.stream.Stream;
    1414
     15import javax.swing.JOptionPane;
    1516import javax.swing.JScrollPane;
    1617
     
    2627import org.openstreetmap.josm.testutils.mockers.HelpAwareOptionPaneMocker;
    2728import org.openstreetmap.josm.testutils.mockers.JOptionPaneSimpleMocker;
     29
    2830import com.google.common.collect.ImmutableMap;
    2931
     
    5860    public void testBuildListOfPluginsToLoad() {
    5961        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         );
     62        final HelpAwareOptionPaneMocker haMocker = new HelpAwareOptionPaneMocker(
     63                PluginHandler.UNMAINTAINED_PLUGINS.stream().collect(
     64                Collectors.toMap(PluginHandler::getUnmaintainedPluginMessage, p -> "Disable plugin")));
     65        final JOptionPaneSimpleMocker jopsMocker = new JOptionPaneSimpleMocker();
     66        jopsMocker.getMockResultMap().put(
     67                PluginHandler.getRemovedPluginsMessage(PluginHandler.DEPRECATED_PLUGINS),
     68                JOptionPane.OK_OPTION
     69            );
    7070        final String old = System.getProperty("josm.plugins");
    7171        try {
     
    8686        }
    8787
    88         assertEquals(1, haMocker.getInvocationLog().size());
    89         Object[] invocationLogEntry = haMocker.getInvocationLog().get(0);
     88        assertEquals(1, jopsMocker.getInvocationLog().size());
     89        Object[] invocationLogEntry = jopsMocker.getInvocationLog().get(0);
    9090        assertEquals(0, (int) invocationLogEntry[0]);
    9191        assertEquals("Warning", invocationLogEntry[2]);
     92
     93        assertEquals(PluginHandler.UNMAINTAINED_PLUGINS.size(), haMocker.getInvocationLog().size());
     94        invocationLogEntry = haMocker.getInvocationLog().get(0);
     95        assertEquals(0, (int) invocationLogEntry[0]);
     96        assertEquals("Disable plugin", invocationLogEntry[2]);
    9297    }
    9398
Note: See TracChangeset for help on using the changeset viewer.