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

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

see #15229 - deprecate Main.platform and related methods - new class PlatformManager

  • 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 com.google.common.collect.ImmutableMap;
24
25import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
26
27/**
28 * Unit tests of {@link PluginPreference} class.
29 */
30public class PluginPreferenceTest {
31 /**
32 * Setup test.
33 */
34 @Rule
35 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
36 public JOSMTestRules test = new JOSMTestRules().preferences().assertionsInEDT();
37
38 /**
39 * Unit test of {@link PluginPreference#PluginPreference}.
40 */
41 @Test
42 public void testPluginPreference() {
43 assertNotNull(new PluginPreference.Factory().createPreferenceSetting());
44 }
45
46 /**
47 * Returns a dummy plugin information.
48 * @return a dummy plugin information
49 * @throws PluginException if an error occurs
50 */
51 public static PluginInformation getDummyPluginInformation() throws PluginException {
52 return new PluginInformation(
53 new File(TestUtils.getTestDataRoot() + "__files/plugin/dummy_plugin.v31772.jar"), "dummy_plugin");
54 }
55
56 /**
57 * Unit test of {@link PluginPreference#buildDownloadSummary}.
58 * @throws Exception if an error occurs
59 */
60 @Test
61 public void testBuildDownloadSummary() throws Exception {
62 final PluginInformation dummy = getDummyPluginInformation();
63 assertEquals("", PluginPreference.buildDownloadSummary(
64 new PluginDownloadTask(NullProgressMonitor.INSTANCE, Collections.<PluginInformation>emptyList(), "")));
65 assertEquals("", PluginPreference.buildDownloadSummary(
66 new PluginDownloadTask(NullProgressMonitor.INSTANCE, Arrays.asList(dummy), "")));
67 assertEquals("The following plugin has been downloaded <strong>successfully</strong>:<ul><li>dummy_plugin (31772)</li></ul>"+
68 "Downloading the following plugin has <strong>failed</strong>:<ul><li>dummy_plugin</li></ul>"+
69 "<br>Error message(untranslated): test",
70 PluginPreference.buildDownloadSummary(
71 new PluginDownloadTask(NullProgressMonitor.INSTANCE, Arrays.asList(dummy), "") {
72 @Override
73 public Collection<PluginInformation> getFailedPlugins() {
74 return Collections.singleton(dummy);
75 }
76
77 @Override
78 public Collection<PluginInformation> getDownloadedPlugins() {
79 return Collections.singleton(dummy);
80 }
81
82 @Override
83 public Exception getLastException() {
84 return new Exception("test");
85 }
86 }));
87 }
88
89 /**
90 * Unit test of {@link PluginPreference#notifyDownloadResults}.
91 */
92 @Test
93 public void testNotifyDownloadResults() {
94 new HelpAwareOptionPaneMocker(ImmutableMap.<String, Object>builder()
95 .put("<html></html>", "OK") // (buildDownloadSummary() output was empty)
96 .put("<html>Please restart JOSM to activate the downloaded plugins.</html>", "OK")
97 .build()
98 );
99
100 PluginDownloadTask task = new PluginDownloadTask(NullProgressMonitor.INSTANCE, Collections.<PluginInformation>emptyList(), "");
101 PluginPreference.notifyDownloadResults(null, task, false);
102 PluginPreference.notifyDownloadResults(null, task, true);
103 }
104
105 /**
106 * Unit test of {@link PluginPreference#addGui}.
107 */
108 @Test
109 public void testAddGui() {
110 PreferencesTestUtils.doTestPreferenceSettingAddGui(new PluginPreference.Factory(), null);
111 }
112}
Note: See TracBrowser for help on using the repository browser.