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.PreferenceTabbedPane;
|
---|
17 | import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
|
---|
18 | import org.openstreetmap.josm.plugins.PluginDownloadTask;
|
---|
19 | import org.openstreetmap.josm.plugins.PluginInformation;
|
---|
20 |
|
---|
21 | /**
|
---|
22 | * Unit tests of {@link PluginPreference} class.
|
---|
23 | */
|
---|
24 | public class PluginPreferenceTest {
|
---|
25 |
|
---|
26 | /**
|
---|
27 | * Setup test.
|
---|
28 | */
|
---|
29 | @BeforeClass
|
---|
30 | public static void setUpBeforeClass() {
|
---|
31 | JOSMFixture.createUnitTestFixture().init();
|
---|
32 | }
|
---|
33 |
|
---|
34 | /**
|
---|
35 | * Unit test of {@link PluginPreference#PluginPreference}.
|
---|
36 | */
|
---|
37 | @Test
|
---|
38 | public void testPluginPreference() {
|
---|
39 | assertNotNull(new PluginPreference.Factory().createPreferenceSetting());
|
---|
40 | }
|
---|
41 |
|
---|
42 | /**
|
---|
43 | * Unit test of {@link PluginPreference#buildDownloadSummary}.
|
---|
44 | * @throws Exception if an error occurs
|
---|
45 | */
|
---|
46 | @Test
|
---|
47 | public void testBuildDownloadSummary() throws Exception {
|
---|
48 | final PluginInformation dummy = new PluginInformation(
|
---|
49 | new File(TestUtils.getTestDataRoot() + "plugin/dummy_plugin.jar"), "dummy_plugin");
|
---|
50 | assertEquals("", PluginPreference.buildDownloadSummary(
|
---|
51 | new PluginDownloadTask(NullProgressMonitor.INSTANCE, Collections.<PluginInformation>emptyList(), "")));
|
---|
52 | assertEquals("", PluginPreference.buildDownloadSummary(
|
---|
53 | new PluginDownloadTask(NullProgressMonitor.INSTANCE, Arrays.asList(dummy), "")));
|
---|
54 | assertEquals("The following plugin has been downloaded <strong>successfully</strong>:<ul><li>dummy_plugin (31772)</li></ul>"+
|
---|
55 | "Downloading the following plugin has <strong>failed</strong>:<ul><li>dummy_plugin</li></ul>",
|
---|
56 | PluginPreference.buildDownloadSummary(
|
---|
57 | new PluginDownloadTask(NullProgressMonitor.INSTANCE, Arrays.asList(dummy), "") {
|
---|
58 | @Override
|
---|
59 | public Collection<PluginInformation> getFailedPlugins() {
|
---|
60 | return Collections.singleton(dummy);
|
---|
61 | }
|
---|
62 |
|
---|
63 | @Override
|
---|
64 | public Collection<PluginInformation> getDownloadedPlugins() {
|
---|
65 | return Collections.singleton(dummy);
|
---|
66 | }
|
---|
67 | }));
|
---|
68 | }
|
---|
69 |
|
---|
70 | /**
|
---|
71 | * Unit test of {@link PluginPreference#notifyDownloadResults}.
|
---|
72 | */
|
---|
73 | @Test
|
---|
74 | public void testNotifyDownloadResults() {
|
---|
75 | PluginDownloadTask task = new PluginDownloadTask(NullProgressMonitor.INSTANCE, Collections.<PluginInformation>emptyList(), "");
|
---|
76 | PluginPreference.notifyDownloadResults(null, task, false);
|
---|
77 | PluginPreference.notifyDownloadResults(null, task, true);
|
---|
78 | }
|
---|
79 |
|
---|
80 | /**
|
---|
81 | * Unit test of {@link PluginPreference#addGui}.
|
---|
82 | */
|
---|
83 | @Test
|
---|
84 | public void testAddGui() {
|
---|
85 | new PluginPreference.Factory().createPreferenceSetting().addGui(new PreferenceTabbedPane());
|
---|
86 | }
|
---|
87 | }
|
---|