source: josm/trunk/test/unit/org/openstreetmap/josm/gui/preferences/plugin/PluginPreferenceTest.java@ 16160

Last change on this file since 16160 was 16160, checked in by simon04, 4 years ago

see #18948 - Get rid of remaining ImmutableMap.of

  • Property svn:eol-style set to native
File size: 4.3 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.preferences.plugin;
3
4import static org.junit.Assert.assertEquals;
5import static org.junit.Assert.assertNotNull;
6
7import java.io.File;
8import java.util.Arrays;
9import java.util.Collection;
10import java.util.Collections;
11
12import org.junit.Rule;
13import org.junit.Test;
14import org.openstreetmap.josm.TestUtils;
15import org.openstreetmap.josm.gui.preferences.PreferencesTestUtils;
16import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
17import org.openstreetmap.josm.plugins.PluginDownloadTask;
18import org.openstreetmap.josm.plugins.PluginException;
19import org.openstreetmap.josm.plugins.PluginInformation;
20import org.openstreetmap.josm.testutils.mockers.HelpAwareOptionPaneMocker;
21import org.openstreetmap.josm.testutils.JOSMTestRules;
22
23import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
24
25/**
26 * Unit tests of {@link PluginPreference} class.
27 */
28public class PluginPreferenceTest {
29 /**
30 * Setup test.
31 */
32 @Rule
33 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
34 public JOSMTestRules test = new JOSMTestRules().preferences().assertionsInEDT();
35
36 /**
37 * Unit test of {@link PluginPreference#PluginPreference}.
38 */
39 @Test
40 public void testPluginPreference() {
41 assertNotNull(new PluginPreference.Factory().createPreferenceSetting());
42 }
43
44 /**
45 * Returns a dummy plugin information.
46 * @return a dummy plugin information
47 * @throws PluginException if an error occurs
48 */
49 public static PluginInformation getDummyPluginInformation() throws PluginException {
50 return new PluginInformation(
51 new File(TestUtils.getTestDataRoot() + "__files/plugin/dummy_plugin.v31772.jar"), "dummy_plugin");
52 }
53
54 /**
55 * Unit test of {@link PluginPreference#buildDownloadSummary}.
56 * @throws Exception if an error occurs
57 */
58 @Test
59 public void testBuildDownloadSummary() throws Exception {
60 final PluginInformation dummy = getDummyPluginInformation();
61 assertEquals("", PluginPreference.buildDownloadSummary(
62 new PluginDownloadTask(NullProgressMonitor.INSTANCE, Collections.<PluginInformation>emptyList(), "")));
63 assertEquals("", PluginPreference.buildDownloadSummary(
64 new PluginDownloadTask(NullProgressMonitor.INSTANCE, Arrays.asList(dummy), "")));
65 assertEquals("The following plugin has been downloaded <strong>successfully</strong>:<ul><li>dummy_plugin (31772)</li></ul>"+
66 "Downloading the following plugin has <strong>failed</strong>:<ul><li>dummy_plugin</li></ul>"+
67 "<br>Error message(untranslated): test",
68 PluginPreference.buildDownloadSummary(
69 new PluginDownloadTask(NullProgressMonitor.INSTANCE, Arrays.asList(dummy), "") {
70 @Override
71 public Collection<PluginInformation> getFailedPlugins() {
72 return Collections.singleton(dummy);
73 }
74
75 @Override
76 public Collection<PluginInformation> getDownloadedPlugins() {
77 return Collections.singleton(dummy);
78 }
79
80 @Override
81 public Exception getLastException() {
82 return new Exception("test");
83 }
84 }));
85 }
86
87 /**
88 * Unit test of {@link PluginPreference#notifyDownloadResults}.
89 */
90 @Test
91 public void testNotifyDownloadResults() {
92 final HelpAwareOptionPaneMocker mocker = new HelpAwareOptionPaneMocker();
93 mocker.getMockResultMap().put("<html></html>", "OK"); // (buildDownloadSummary() output was empty)
94 mocker.getMockResultMap().put("<html>Please restart JOSM to activate the downloaded plugins.</html>", "OK");
95
96 PluginDownloadTask task = new PluginDownloadTask(NullProgressMonitor.INSTANCE, Collections.<PluginInformation>emptyList(), "");
97 PluginPreference.notifyDownloadResults(null, task, false);
98 PluginPreference.notifyDownloadResults(null, task, true);
99 }
100
101 /**
102 * Unit test of {@link PluginPreference#addGui}.
103 */
104 @Test
105 public void testAddGui() {
106 PreferencesTestUtils.doTestPreferenceSettingAddGui(new PluginPreference.Factory(), null);
107 }
108}
Note: See TracBrowser for help on using the repository browser.