source: josm/trunk/test/unit/org/openstreetmap/josm/plugins/PluginHandlerTest.java@ 12842

Last change on this file since 12842 was 12754, checked in by Don-vip, 7 years ago

see #15229 - see #15182 - see #13036 - update unit tests

  • Property svn:eol-style set to native
File size: 4.0 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.plugins;
3
4import static org.junit.Assert.assertEquals;
5import static org.junit.Assert.assertFalse;
6import static org.junit.Assert.assertNotNull;
7import static org.junit.Assert.assertTrue;
8
9import java.util.ArrayList;
10import java.util.Arrays;
11import java.util.List;
12
13import org.junit.Rule;
14import org.junit.Test;
15import org.openstreetmap.josm.Main;
16import org.openstreetmap.josm.gui.preferences.plugin.PluginPreferenceTest;
17import org.openstreetmap.josm.plugins.PluginHandler.DeprecatedPlugin;
18import org.openstreetmap.josm.plugins.PluginHandler.PluginInformationAction;
19import org.openstreetmap.josm.testutils.JOSMTestRules;
20import org.openstreetmap.josm.tools.Utils;
21
22import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
23import nl.jqno.equalsverifier.EqualsVerifier;
24
25/**
26 * Unit tests of {@link PluginHandler} class.
27 */
28public class PluginHandlerTest {
29
30 /**
31 * Setup test.
32 */
33 @Rule
34 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
35 public JOSMTestRules test = new JOSMTestRules().platform();
36
37 /**
38 * Unit test of methods {@link DeprecatedPlugin#equals} and {@link DeprecatedPlugin#hashCode}.
39 */
40 @Test
41 public void testEqualsContract() {
42 EqualsVerifier.forClass(DeprecatedPlugin.class).usingGetClass().verify();
43 }
44
45 /**
46 * Unit test of {@link PluginHandler#buildListOfPluginsToLoad}.
47 */
48 @Test
49 public void testBuildListOfPluginsToLoad() {
50 final String old = System.getProperty("josm.plugins");
51 try {
52 System.setProperty("josm.plugins",
53 Utils.join(",", PluginHandler.DEPRECATED_PLUGINS) + "," +
54 Utils.join(",", Arrays.asList(PluginHandler.UNMAINTAINED_PLUGINS)));
55 List<PluginInformation> list = PluginHandler.buildListOfPluginsToLoad(null, null);
56 assertNotNull(list);
57 assertTrue(list.isEmpty());
58 } finally {
59 if (old != null) {
60 System.setProperty("josm.plugins", old);
61 } else {
62 System.clearProperty("josm.plugins");
63 }
64 }
65 }
66
67 /**
68 * Unit test of {@link PluginHandler#filterDeprecatedPlugins}.
69 */
70 @Test
71 public void testFilterDeprecatedPlugins() {
72 List<String> plugins = new ArrayList<>(Arrays.asList("foo", "bar", "imagery"));
73 PluginHandler.filterDeprecatedPlugins(Main.parent, plugins);
74 assertEquals(2, plugins.size());
75 assertFalse(plugins.contains("imagery"));
76 }
77
78 /**
79 * Unit test of {@link PluginHandler#filterUnmaintainedPlugins}.
80 */
81 @Test
82 public void testFilterUnmaintainedPlugins() {
83 List<String> plugins = new ArrayList<>(Arrays.asList("foo", "bar", "gpsbabelgui"));
84 PluginHandler.filterUnmaintainedPlugins(Main.parent, plugins);
85 assertEquals(2, plugins.size());
86 assertFalse(plugins.contains("gpsbabelgui"));
87 }
88
89 /**
90 * Unit test of {@link PluginInformationAction} class.
91 * @throws PluginException if an error occurs
92 */
93 @Test
94 public void testPluginInformationAction() throws PluginException {
95 PluginInformationAction action = new PluginInformationAction(PluginPreferenceTest.getDummyPluginInformation());
96 assertEquals(
97 "Ant-Version: Apache Ant 1.9.6\n" +
98 "Author: Don-vip\n" +
99 "Created-By: 1.7.0_91-b02 (Oracle Corporation)\n" +
100 "Manifest-Version: 1.0\n" +
101 "Plugin-Canloadatruntime: true\n" +
102 "Plugin-Class: org.openstreetmap.josm.plugins.fr.epci.EpciPlugin\n" +
103 "Plugin-Date: 2015-11-19T08:21:07.645033Z\n" +
104 "Plugin-Description: Handling of French EPCIs (boundary=local_authority)\n" +
105 "Plugin-Early: true\n" +
106 "Plugin-Link: http://wiki.openstreetmap.org/wiki/FR:JOSM/Fr:Plugin/EPCI-fr\n" +
107 "Plugin-Mainversion: 7001\n" +
108 "Plugin-Version: 31772\n", action.getText());
109 action.actionPerformed(null);
110 }
111}
Note: See TracBrowser for help on using the repository browser.