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

Last change on this file since 11974 was 11974, checked in by Don-vip, 7 years ago

add unit tests, javadoc

  • Property svn:eol-style set to native
File size: 3.8 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.BeforeClass;
13import org.junit.Test;
14import org.openstreetmap.josm.JOSMFixture;
15import org.openstreetmap.josm.TestUtils;
16import org.openstreetmap.josm.gui.preferences.PreferencesTestUtils;
17import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
18import org.openstreetmap.josm.plugins.PluginDownloadTask;
19import org.openstreetmap.josm.plugins.PluginException;
20import org.openstreetmap.josm.plugins.PluginInformation;
21
22/**
23 * Unit tests of {@link PluginPreference} class.
24 */
25public 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}
Note: See TracBrowser for help on using the repository browser.