1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui;
|
---|
3 |
|
---|
4 | import static org.junit.Assert.assertEquals;
|
---|
5 | import static org.junit.Assert.assertNotNull;
|
---|
6 | import static org.junit.Assert.assertNull;
|
---|
7 |
|
---|
8 | import java.util.Collection;
|
---|
9 |
|
---|
10 | import javax.swing.event.ChangeEvent;
|
---|
11 | import javax.swing.event.ChangeListener;
|
---|
12 |
|
---|
13 | import org.junit.BeforeClass;
|
---|
14 | import org.junit.Test;
|
---|
15 | import org.openstreetmap.josm.JOSMFixture;
|
---|
16 | import org.openstreetmap.josm.gui.SplashScreen.SplashProgressMonitor;
|
---|
17 | import org.openstreetmap.josm.plugins.PluginHandler;
|
---|
18 | import org.openstreetmap.josm.plugins.PluginInformation;
|
---|
19 |
|
---|
20 | /**
|
---|
21 | * Unit tests of {@link MainApplication} class.
|
---|
22 | */
|
---|
23 | public class MainApplicationTest {
|
---|
24 |
|
---|
25 | /**
|
---|
26 | * Setup test.
|
---|
27 | */
|
---|
28 | @BeforeClass
|
---|
29 | public static void setUp() {
|
---|
30 | JOSMFixture.createUnitTestFixture().init(true);
|
---|
31 | }
|
---|
32 |
|
---|
33 | /**
|
---|
34 | * Test of {@link MainApplication#updateAndLoadEarlyPlugins} and {@link MainApplication#loadLatePlugins} methods.
|
---|
35 | */
|
---|
36 | @Test
|
---|
37 | public void testUpdateAndLoadPlugins() {
|
---|
38 | final String old = System.getProperty("josm.plugins");
|
---|
39 | try {
|
---|
40 | System.setProperty("josm.plugins", "buildings_tools,plastic_laf");
|
---|
41 | assertEquals("buildings_tools,plastic_laf", System.getProperty("josm.plugins"));
|
---|
42 | SplashProgressMonitor monitor = new SplashProgressMonitor("foo", new ChangeListener() {
|
---|
43 | @Override
|
---|
44 | public void stateChanged(ChangeEvent e) {
|
---|
45 | // Do nothing
|
---|
46 | }
|
---|
47 | });
|
---|
48 | Collection<PluginInformation> plugins = MainApplication.updateAndLoadEarlyPlugins(null, monitor);
|
---|
49 | assertEquals("buildings_tools,plastic_laf", System.getProperty("josm.plugins"));
|
---|
50 | assertEquals(2, plugins.size());
|
---|
51 | assertNotNull(PluginHandler.getPlugin("plastic_laf"));
|
---|
52 | assertNull(PluginHandler.getPlugin("buildings_tools"));
|
---|
53 | MainApplication.loadLatePlugins(null, monitor, plugins);
|
---|
54 | assertNotNull(PluginHandler.getPlugin("buildings_tools"));
|
---|
55 | } finally {
|
---|
56 | if (old != null) {
|
---|
57 | System.setProperty("josm.plugins", old);
|
---|
58 | } else {
|
---|
59 | System.clearProperty("josm.plugins");
|
---|
60 | }
|
---|
61 | }
|
---|
62 | }
|
---|
63 | }
|
---|