| 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 | SplashProgressMonitor monitor = new SplashProgressMonitor("foo", new ChangeListener() {
|
|---|
| 42 | @Override
|
|---|
| 43 | public void stateChanged(ChangeEvent e) {
|
|---|
| 44 | // Do nothing
|
|---|
| 45 | }
|
|---|
| 46 | });
|
|---|
| 47 | Collection<PluginInformation> plugins = MainApplication.updateAndLoadEarlyPlugins(null, monitor);
|
|---|
| 48 | assertEquals(2, plugins.size());
|
|---|
| 49 | assertNotNull(PluginHandler.getPlugin("plastic_laf"));
|
|---|
| 50 | assertNull(PluginHandler.getPlugin("buildings_tools"));
|
|---|
| 51 | MainApplication.loadLatePlugins(null, monitor, plugins);
|
|---|
| 52 | assertNotNull(PluginHandler.getPlugin("buildings_tools"));
|
|---|
| 53 | } finally {
|
|---|
| 54 | if (old != null) {
|
|---|
| 55 | System.setProperty("josm.plugins", old);
|
|---|
| 56 | } else {
|
|---|
| 57 | System.clearProperty("josm.plugins");
|
|---|
| 58 | }
|
|---|
| 59 | }
|
|---|
| 60 | }
|
|---|
| 61 | }
|
|---|