1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm;
|
---|
3 |
|
---|
4 | import static org.junit.Assert.assertEquals;
|
---|
5 | import static org.junit.Assert.assertNotNull;
|
---|
6 | import static org.junit.Assert.assertNull;
|
---|
7 | import static org.junit.Assert.assertTrue;
|
---|
8 |
|
---|
9 | import java.util.Collection;
|
---|
10 |
|
---|
11 | import javax.swing.UIManager;
|
---|
12 |
|
---|
13 | import org.junit.Rule;
|
---|
14 | import org.junit.Test;
|
---|
15 | import org.openstreetmap.josm.Main.DownloadParamType;
|
---|
16 | import org.openstreetmap.josm.testutils.JOSMTestRules;
|
---|
17 |
|
---|
18 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
---|
19 |
|
---|
20 | /**
|
---|
21 | * Unit tests of {@link Main} class.
|
---|
22 | */
|
---|
23 | public class MainTest {
|
---|
24 |
|
---|
25 | /**
|
---|
26 | * Setup test.
|
---|
27 | */
|
---|
28 | @Rule
|
---|
29 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
---|
30 | public JOSMTestRules test = new JOSMTestRules().platform();
|
---|
31 |
|
---|
32 | /**
|
---|
33 | * Unit test of {@link DownloadParamType#paramType} method.
|
---|
34 | */
|
---|
35 | @Test
|
---|
36 | public void testParamType() {
|
---|
37 | assertEquals(DownloadParamType.bounds, DownloadParamType.paramType("48.000,16.000,48.001,16.001"));
|
---|
38 | assertEquals(DownloadParamType.fileName, DownloadParamType.paramType("data.osm"));
|
---|
39 | assertEquals(DownloadParamType.fileUrl, DownloadParamType.paramType("file:///home/foo/data.osm"));
|
---|
40 | assertEquals(DownloadParamType.fileUrl, DownloadParamType.paramType("file://C:\\Users\\foo\\data.osm"));
|
---|
41 | assertEquals(DownloadParamType.httpUrl, DownloadParamType.paramType("http://somewhere.com/data.osm"));
|
---|
42 | assertEquals(DownloadParamType.httpUrl, DownloadParamType.paramType("https://somewhere.com/data.osm"));
|
---|
43 | }
|
---|
44 |
|
---|
45 | /**
|
---|
46 | * Unit tests on log messages.
|
---|
47 | */
|
---|
48 | @Test
|
---|
49 | @SuppressFBWarnings(value = "ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD")
|
---|
50 | public void testLogs() {
|
---|
51 |
|
---|
52 | assertNull(Main.getErrorMessage(null));
|
---|
53 |
|
---|
54 | // Correct behaviour with errors
|
---|
55 | Main.error(new Exception("exception_error"));
|
---|
56 | Main.error("Error message on one line");
|
---|
57 | Main.error("First line of error message on several lines\nline2\nline3\nline4");
|
---|
58 | Collection<String> errors = Main.getLastErrorAndWarnings();
|
---|
59 | assertTrue(errors.contains("E: java.lang.Exception: exception_error"));
|
---|
60 | assertTrue(errors.contains("E: Error message on one line"));
|
---|
61 | assertTrue(errors.contains("E: First line of error message on several lines"));
|
---|
62 |
|
---|
63 | // Correct behaviour with warnings
|
---|
64 | Main.warn(new Exception("exception_warn", new Exception("root_cause")));
|
---|
65 | Main.warn("Warning message on one line");
|
---|
66 | Main.warn("First line of warning message on several lines\nline2\nline3\nline4");
|
---|
67 | Collection<String> warnings = Main.getLastErrorAndWarnings();
|
---|
68 | assertTrue(warnings.contains("W: java.lang.Exception: exception_warn. Cause: java.lang.Exception: root_cause"));
|
---|
69 | assertTrue(warnings.contains("W: Warning message on one line"));
|
---|
70 | assertTrue(warnings.contains("W: First line of warning message on several lines"));
|
---|
71 | }
|
---|
72 |
|
---|
73 | /**
|
---|
74 | * Unit test of {@link Main#preConstructorInit}.
|
---|
75 | */
|
---|
76 | @Test
|
---|
77 | public void testPreConstructorInit() {
|
---|
78 | Main.preConstructorInit();
|
---|
79 | assertNotNull(Main.getProjection());
|
---|
80 | assertEquals(Main.pref.get("laf", Main.platform.getDefaultStyle()), UIManager.getLookAndFeel().getClass().getCanonicalName());
|
---|
81 | assertNotNull(Main.toolbar);
|
---|
82 | }
|
---|
83 | }
|
---|