1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.preferences.plugin;
|
---|
3 |
|
---|
4 | import static org.junit.Assert.assertEquals;
|
---|
5 | import static org.junit.Assert.assertNotNull;
|
---|
6 |
|
---|
7 | import java.io.File;
|
---|
8 | import java.util.Arrays;
|
---|
9 | import java.util.Collection;
|
---|
10 | import java.util.Collections;
|
---|
11 |
|
---|
12 | import org.junit.BeforeClass;
|
---|
13 | import org.junit.Test;
|
---|
14 | import org.openstreetmap.josm.JOSMFixture;
|
---|
15 | import org.openstreetmap.josm.TestUtils;
|
---|
16 | import org.openstreetmap.josm.gui.preferences.PreferencesTestUtils;
|
---|
17 | import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
|
---|
18 | import org.openstreetmap.josm.plugins.PluginDownloadTask;
|
---|
19 | import org.openstreetmap.josm.plugins.PluginException;
|
---|
20 | import org.openstreetmap.josm.plugins.PluginInformation;
|
---|
21 |
|
---|
22 | /**
|
---|
23 | * Unit tests of {@link PluginPreference} class.
|
---|
24 | */
|
---|
25 | public class PluginPreferenceTest {
|
---|
26 |
|
---|
27 | /**
|
---|
28 | * Setup test.
|
---|
29 | */
|
---|
30 | @BeforeClass
|
---|
31 | public static void setUpBeforeClass() {
|
---|
32 | JOSMFixture.createUnitTestFixture().init();
|
---|
33 | }
|
---|
34 |
|
---|
35 | /**
|
---|
36 | * Unit test of {@link PluginPreference#PluginPreference}.
|
---|
37 | */
|
---|
38 | @Test
|
---|
39 | public void testPluginPreference() {
|
---|
40 | assertNotNull(new PluginPreference.Factory().createPreferenceSetting());
|
---|
41 | }
|
---|
42 |
|
---|
43 | /**
|
---|
44 | * Returns a dummy plugin information.
|
---|
45 | * @return a dummy plugin information
|
---|
46 | * @throws PluginException if an error occurs
|
---|
47 | */
|
---|
48 | public static PluginInformation getDummyPluginInformation() throws PluginException {
|
---|
49 | return new PluginInformation(
|
---|
50 | new File(TestUtils.getTestDataRoot() + "plugin/dummy_plugin.jar"), "dummy_plugin");
|
---|
51 | }
|
---|
52 |
|
---|
53 | /**
|
---|
54 | * Unit test of {@link PluginPreference#buildDownloadSummary}.
|
---|
55 | * @throws Exception if an error occurs
|
---|
56 | */
|
---|
57 | @Test
|
---|
58 | public void testBuildDownloadSummary() throws Exception {
|
---|
59 | final PluginInformation dummy = getDummyPluginInformation();
|
---|
60 | assertEquals("", PluginPreference.buildDownloadSummary(
|
---|
61 | new PluginDownloadTask(NullProgressMonitor.INSTANCE, Collections.<PluginInformation>emptyList(), "")));
|
---|
62 | assertEquals("", PluginPreference.buildDownloadSummary(
|
---|
63 | new PluginDownloadTask(NullProgressMonitor.INSTANCE, Arrays.asList(dummy), "")));
|
---|
64 | assertEquals("The following plugin has been downloaded <strong>successfully</strong>:<ul><li>dummy_plugin (31772)</li></ul>"+
|
---|
65 | "Downloading the following plugin has <strong>failed</strong>:<ul><li>dummy_plugin</li></ul>"+
|
---|
66 | "<br>Error message(untranslated): test",
|
---|
67 | PluginPreference.buildDownloadSummary(
|
---|
68 | new PluginDownloadTask(NullProgressMonitor.INSTANCE, Arrays.asList(dummy), "") {
|
---|
69 | @Override
|
---|
70 | public Collection<PluginInformation> getFailedPlugins() {
|
---|
71 | return Collections.singleton(dummy);
|
---|
72 | }
|
---|
73 |
|
---|
74 | @Override
|
---|
75 | public Collection<PluginInformation> getDownloadedPlugins() {
|
---|
76 | return Collections.singleton(dummy);
|
---|
77 | }
|
---|
78 |
|
---|
79 | @Override
|
---|
80 | public Exception getLastException() {
|
---|
81 | return new Exception("test");
|
---|
82 | }
|
---|
83 | }));
|
---|
84 | }
|
---|
85 |
|
---|
86 | /**
|
---|
87 | * Unit test of {@link PluginPreference#notifyDownloadResults}.
|
---|
88 | */
|
---|
89 | @Test
|
---|
90 | public void testNotifyDownloadResults() {
|
---|
91 | PluginDownloadTask task = new PluginDownloadTask(NullProgressMonitor.INSTANCE, Collections.<PluginInformation>emptyList(), "");
|
---|
92 | PluginPreference.notifyDownloadResults(null, task, false);
|
---|
93 | PluginPreference.notifyDownloadResults(null, task, true);
|
---|
94 | }
|
---|
95 |
|
---|
96 | /**
|
---|
97 | * Unit test of {@link PluginPreference#addGui}.
|
---|
98 | */
|
---|
99 | @Test
|
---|
100 | public void testAddGui() {
|
---|
101 | PreferencesTestUtils.doTestPreferenceSettingAddGui(new PluginPreference.Factory(), null);
|
---|
102 | }
|
---|
103 | }
|
---|