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

Last change on this file since 13812 was 13079, checked in by Don-vip, 6 years ago

see #15560 - EqualsVerifier does not work with newer Java versions -> disable tests automatically in this case
Workaround to https://github.com/jqno/equalsverifier/issues/177 / https://github.com/raphw/byte-buddy/issues/370
Inspired by https://issues.apache.org/jira/browse/SOLR-11606

  • Property svn:eol-style set to native
File size: 4.1 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.TestUtils;
17import org.openstreetmap.josm.gui.preferences.plugin.PluginPreferenceTest;
18import org.openstreetmap.josm.plugins.PluginHandler.DeprecatedPlugin;
19import org.openstreetmap.josm.plugins.PluginHandler.PluginInformationAction;
20import org.openstreetmap.josm.testutils.JOSMTestRules;
21import org.openstreetmap.josm.tools.Utils;
22
23import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
24import nl.jqno.equalsverifier.EqualsVerifier;
25
26/**
27 * Unit tests of {@link PluginHandler} class.
28 */
29public class PluginHandlerTest {
30
31 /**
32 * Setup test.
33 */
34 @Rule
35 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
36 public JOSMTestRules test = new JOSMTestRules().platform();
37
38 /**
39 * Unit test of methods {@link DeprecatedPlugin#equals} and {@link DeprecatedPlugin#hashCode}.
40 */
41 @Test
42 public void testEqualsContract() {
43 TestUtils.assumeWorkingEqualsVerifier();
44 EqualsVerifier.forClass(DeprecatedPlugin.class).usingGetClass().verify();
45 }
46
47 /**
48 * Unit test of {@link PluginHandler#buildListOfPluginsToLoad}.
49 */
50 @Test
51 public void testBuildListOfPluginsToLoad() {
52 final String old = System.getProperty("josm.plugins");
53 try {
54 System.setProperty("josm.plugins",
55 Utils.join(",", PluginHandler.DEPRECATED_PLUGINS) + "," +
56 Utils.join(",", Arrays.asList(PluginHandler.UNMAINTAINED_PLUGINS)));
57 List<PluginInformation> list = PluginHandler.buildListOfPluginsToLoad(null, null);
58 assertNotNull(list);
59 assertTrue(list.isEmpty());
60 } finally {
61 if (old != null) {
62 System.setProperty("josm.plugins", old);
63 } else {
64 System.clearProperty("josm.plugins");
65 }
66 }
67 }
68
69 /**
70 * Unit test of {@link PluginHandler#filterDeprecatedPlugins}.
71 */
72 @Test
73 public void testFilterDeprecatedPlugins() {
74 List<String> plugins = new ArrayList<>(Arrays.asList("foo", "bar", "imagery"));
75 PluginHandler.filterDeprecatedPlugins(Main.parent, plugins);
76 assertEquals(2, plugins.size());
77 assertFalse(plugins.contains("imagery"));
78 }
79
80 /**
81 * Unit test of {@link PluginHandler#filterUnmaintainedPlugins}.
82 */
83 @Test
84 public void testFilterUnmaintainedPlugins() {
85 List<String> plugins = new ArrayList<>(Arrays.asList("foo", "bar", "gpsbabelgui"));
86 PluginHandler.filterUnmaintainedPlugins(Main.parent, plugins);
87 assertEquals(2, plugins.size());
88 assertFalse(plugins.contains("gpsbabelgui"));
89 }
90
91 /**
92 * Unit test of {@link PluginInformationAction} class.
93 * @throws PluginException if an error occurs
94 */
95 @Test
96 public void testPluginInformationAction() throws PluginException {
97 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());
111 action.actionPerformed(null);
112 }
113}
Note: See TracBrowser for help on using the repository browser.