1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.plugins;
|
---|
3 |
|
---|
4 | import static org.junit.Assert.assertEquals;
|
---|
5 | import static org.junit.Assert.assertFalse;
|
---|
6 | import static org.junit.Assert.assertNotNull;
|
---|
7 | import static org.junit.Assert.assertTrue;
|
---|
8 |
|
---|
9 | import java.util.ArrayList;
|
---|
10 | import java.util.Arrays;
|
---|
11 | import java.util.List;
|
---|
12 |
|
---|
13 | import org.junit.BeforeClass;
|
---|
14 | import org.junit.Test;
|
---|
15 | import org.openstreetmap.josm.JOSMFixture;
|
---|
16 | import org.openstreetmap.josm.Main;
|
---|
17 | import org.openstreetmap.josm.plugins.PluginHandler.DeprecatedPlugin;
|
---|
18 | import org.openstreetmap.josm.tools.Utils;
|
---|
19 |
|
---|
20 | import nl.jqno.equalsverifier.EqualsVerifier;
|
---|
21 |
|
---|
22 | /**
|
---|
23 | * Unit tests of {@link PluginHandler} class.
|
---|
24 | */
|
---|
25 | public class PluginHandlerTest {
|
---|
26 |
|
---|
27 | /**
|
---|
28 | * Setup test.
|
---|
29 | */
|
---|
30 | @BeforeClass
|
---|
31 | public static void setUp() {
|
---|
32 | JOSMFixture.createUnitTestFixture().init();
|
---|
33 | }
|
---|
34 |
|
---|
35 | /**
|
---|
36 | * Unit test of methods {@link DeprecatedPlugin#equals} and {@link DeprecatedPlugin#hashCode}.
|
---|
37 | */
|
---|
38 | @Test
|
---|
39 | public void equalsContract() {
|
---|
40 | EqualsVerifier.forClass(DeprecatedPlugin.class).usingGetClass().verify();
|
---|
41 | }
|
---|
42 |
|
---|
43 | /**
|
---|
44 | * Unit test of {@link PluginHandler#buildListOfPluginsToLoad}.
|
---|
45 | */
|
---|
46 | @Test
|
---|
47 | public void testBuildListOfPluginsToLoad() {
|
---|
48 | final String old = System.getProperty("josm.plugins");
|
---|
49 | try {
|
---|
50 | System.setProperty("josm.plugins",
|
---|
51 | Utils.join(",", PluginHandler.DEPRECATED_PLUGINS) + "," +
|
---|
52 | Utils.join(",", Arrays.asList(PluginHandler.UNMAINTAINED_PLUGINS)));
|
---|
53 | List<PluginInformation> list = PluginHandler.buildListOfPluginsToLoad(null, null);
|
---|
54 | assertNotNull(list);
|
---|
55 | assertTrue(list.isEmpty());
|
---|
56 | } finally {
|
---|
57 | if (old != null) {
|
---|
58 | System.setProperty("josm.plugins", old);
|
---|
59 | } else {
|
---|
60 | System.clearProperty("josm.plugins");
|
---|
61 | }
|
---|
62 | }
|
---|
63 | }
|
---|
64 |
|
---|
65 | /**
|
---|
66 | * Unit test of {@link PluginHandler#filterDeprecatedPlugins}.
|
---|
67 | */
|
---|
68 | @Test
|
---|
69 | public void testFilterDeprecatedPlugins() {
|
---|
70 | List<String> plugins = new ArrayList<>(Arrays.asList("foo", "bar", "imagery"));
|
---|
71 | PluginHandler.filterDeprecatedPlugins(Main.parent, plugins);
|
---|
72 | assertEquals(2, plugins.size());
|
---|
73 | assertFalse(plugins.contains("imagery"));
|
---|
74 | }
|
---|
75 |
|
---|
76 | /**
|
---|
77 | * Unit test of {@link PluginHandler#filterUnmaintainedPlugins}.
|
---|
78 | */
|
---|
79 | @Test
|
---|
80 | public void testFilterUnmaintainedPlugins() {
|
---|
81 | List<String> plugins = new ArrayList<>(Arrays.asList("foo", "bar", "gpsbabelgui"));
|
---|
82 | PluginHandler.filterUnmaintainedPlugins(Main.parent, plugins);
|
---|
83 | assertEquals(2, plugins.size());
|
---|
84 | assertFalse(plugins.contains("gpsbabelgui"));
|
---|
85 | }
|
---|
86 | }
|
---|