Changeset 14317 in josm for trunk/test/unit/org
- Timestamp:
- 2018-10-13T01:45:52+02:00 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/plugins/PluginHandlerTest.java
r14153 r14317 11 11 import java.util.List; 12 12 13 import javax.swing.JScrollPane; 14 13 15 import org.junit.Rule; 14 16 import org.junit.Test; … … 16 18 import org.openstreetmap.josm.gui.MainApplication; 17 19 import org.openstreetmap.josm.gui.preferences.plugin.PluginPreferenceTest; 20 import org.openstreetmap.josm.gui.widgets.JosmTextArea; 18 21 import org.openstreetmap.josm.plugins.PluginHandler.DeprecatedPlugin; 19 22 import org.openstreetmap.josm.plugins.PluginHandler.PluginInformationAction; 20 23 import org.openstreetmap.josm.testutils.JOSMTestRules; 24 import org.openstreetmap.josm.testutils.mockers.HelpAwareOptionPaneMocker; 25 import org.openstreetmap.josm.testutils.mockers.JOptionPaneSimpleMocker; 21 26 import org.openstreetmap.josm.tools.Utils; 27 28 import com.google.common.collect.ImmutableMap; 22 29 23 30 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; … … 50 57 @Test 51 58 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 ); 52 70 final String old = System.getProperty("josm.plugins"); 53 71 try { … … 65 83 } 66 84 } 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]); 67 90 } 68 91 … … 72 95 @Test 73 96 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 74 106 List<String> plugins = new ArrayList<>(Arrays.asList("foo", "bar", "imagery")); 75 107 PluginHandler.filterDeprecatedPlugins(MainApplication.getMainFrame(), plugins); 76 108 assertEquals(2, plugins.size()); 77 109 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]); 78 115 } 79 116 … … 83 120 @Test 84 121 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 85 132 List<String> plugins = new ArrayList<>(Arrays.asList("foo", "bar", "gpsbabelgui")); 86 133 PluginHandler.filterUnmaintainedPlugins(MainApplication.getMainFrame(), plugins); 87 134 assertEquals(2, plugins.size()); 88 135 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]); 89 141 } 90 142 … … 95 147 @Test 96 148 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 97 170 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()); 111 172 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]); 112 178 } 113 179 }
Note:
See TracChangeset
for help on using the changeset viewer.