source: josm/trunk/test/unit/org/openstreetmap/josm/gui/MainApplicationTest.java@ 10378

Last change on this file since 10378 was 10123, checked in by Don-vip, 8 years ago

fix unit test failing with clean jenkins workspace

  • Property svn:eol-style set to native
File size: 3.0 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui;
3
4import static org.junit.Assert.assertEquals;
5import static org.junit.Assert.assertNotNull;
6import static org.junit.Assert.assertNull;
7
8import java.util.Arrays;
9import java.util.Collection;
10
11import javax.swing.event.ChangeEvent;
12import javax.swing.event.ChangeListener;
13
14import org.junit.BeforeClass;
15import org.junit.Test;
16import org.openstreetmap.josm.JOSMFixture;
17import org.openstreetmap.josm.gui.SplashScreen.SplashProgressMonitor;
18import org.openstreetmap.josm.plugins.PluginHandler;
19import org.openstreetmap.josm.plugins.PluginHandlerTestIT;
20import org.openstreetmap.josm.plugins.PluginInformation;
21import org.openstreetmap.josm.plugins.PluginListParseException;
22import org.openstreetmap.josm.plugins.PluginListParser;
23
24/**
25 * Unit tests of {@link MainApplication} class.
26 */
27public class MainApplicationTest {
28
29 /**
30 * Setup test.
31 */
32 @BeforeClass
33 public static void setUp() {
34 JOSMFixture.createUnitTestFixture().init(true);
35 }
36
37 /**
38 * Test of {@link MainApplication#updateAndLoadEarlyPlugins} and {@link MainApplication#loadLatePlugins} methods.
39 * @throws PluginListParseException if an error occurs
40 */
41 @Test
42 public void testUpdateAndLoadPlugins() throws PluginListParseException {
43 final String old = System.getProperty("josm.plugins");
44 try {
45 System.setProperty("josm.plugins", "buildings_tools,plastic_laf");
46 SplashProgressMonitor monitor = new SplashProgressMonitor("foo", new ChangeListener() {
47 @Override
48 public void stateChanged(ChangeEvent e) {
49 // Do nothing
50 }
51 });
52 Collection<PluginInformation> plugins = MainApplication.updateAndLoadEarlyPlugins(null, monitor);
53 if (plugins.isEmpty()) {
54 PluginHandlerTestIT.downloadPlugins(Arrays.asList(
55 newPluginInformation("buildings_tools"),
56 newPluginInformation("plastic_laf")));
57 plugins = MainApplication.updateAndLoadEarlyPlugins(null, monitor);
58 }
59 assertEquals(2, plugins.size());
60 assertNotNull(PluginHandler.getPlugin("plastic_laf"));
61 assertNull(PluginHandler.getPlugin("buildings_tools"));
62 MainApplication.loadLatePlugins(null, monitor, plugins);
63 assertNotNull(PluginHandler.getPlugin("buildings_tools"));
64 } finally {
65 if (old != null) {
66 System.setProperty("josm.plugins", old);
67 } else {
68 System.clearProperty("josm.plugins");
69 }
70 }
71 }
72
73 private static PluginInformation newPluginInformation(String plugin) throws PluginListParseException {
74 //return new PluginInformation(new File(TestUtils.getTestDataRoot()+File.separator+"plugin"+File.separator+plugin+".jar"));
75 return PluginListParser.createInfo(plugin+".jar", "https://svn.openstreetmap.org/applications/editors/josm/dist/"+plugin+".jar",
76 "");
77 }
78}
Note: See TracBrowser for help on using the repository browser.