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

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

fix #12927 - Move title management and main frame layout to new class (patch by michael2402) - gsoc-core

File size: 3.7 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm;
3
4import static org.junit.Assert.assertEquals;
5import static org.junit.Assert.assertFalse;
6import static org.junit.Assert.assertNull;
7import static org.junit.Assert.assertTrue;
8
9import java.util.Collection;
10
11import org.junit.BeforeClass;
12import org.junit.Test;
13import org.openstreetmap.josm.Main.DownloadParamType;
14import org.openstreetmap.josm.gui.MainApplication;
15
16import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
17
18/**
19 * Unit tests of {@link Main} class.
20 */
21public class MainTest {
22
23 /**
24 * Setup test.
25 */
26 @BeforeClass
27 public static void setUp() {
28 JOSMFixture.createUnitTestFixture().init();
29 }
30
31 /**
32 * Unit test of {@link DownloadParamType#paramType} method.
33 */
34 @Test
35 public void testParamType() {
36 assertEquals(DownloadParamType.bounds, DownloadParamType.paramType("48.000,16.000,48.001,16.001"));
37 assertEquals(DownloadParamType.fileName, DownloadParamType.paramType("data.osm"));
38 assertEquals(DownloadParamType.fileUrl, DownloadParamType.paramType("file:///home/foo/data.osm"));
39 assertEquals(DownloadParamType.fileUrl, DownloadParamType.paramType("file://C:\\Users\\foo\\data.osm"));
40 assertEquals(DownloadParamType.httpUrl, DownloadParamType.paramType("http://somewhere.com/data.osm"));
41 assertEquals(DownloadParamType.httpUrl, DownloadParamType.paramType("https://somewhere.com/data.osm"));
42 }
43
44 /**
45 * Unit test of {@code Main#preConstructorInit}.
46 */
47 @Test
48 public void testPreConstructorInit() {
49 Main.preConstructorInit(MainApplication.buildCommandLineArgumentMap(new String[0]));
50 Main.preConstructorInit(MainApplication.buildCommandLineArgumentMap(new String[]{"--geometry=400x300+10+5", "--no-maximize"}));
51 //assertEquals(new WindowGeometry(new Point(10, 5), new Dimension(400, 300)), Main.geometry); // FIXME see #12927
52 }
53
54 /**
55 * Unit tests on log messages.
56 */
57 @Test
58 @SuppressFBWarnings(value = "ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD")
59 public void testLogs() {
60
61 assertNull(Main.getErrorMessage(null));
62
63 // Correct behaviour with errors
64 Main.error(new Exception("exception_error"));
65 Main.error("Error message on one line");
66 Main.error("First line of error message on several lines\nline2\nline3\nline4");
67 Collection<String> errors = Main.getLastErrorAndWarnings();
68 assertTrue(errors.contains("E: java.lang.Exception: exception_error"));
69 assertTrue(errors.contains("E: Error message on one line"));
70 assertTrue(errors.contains("E: First line of error message on several lines"));
71
72 // Correct behaviour with warnings
73 Main.warn(new Exception("exception_warn", new Exception("root_cause")));
74 Main.warn("Warning message on one line");
75 Main.warn("First line of warning message on several lines\nline2\nline3\nline4");
76 Collection<String> warnings = Main.getLastErrorAndWarnings();
77 assertTrue(warnings.contains("W: java.lang.Exception: exception_warn. Cause: java.lang.Exception: root_cause"));
78 assertTrue(warnings.contains("W: Warning message on one line"));
79 assertTrue(warnings.contains("W: First line of warning message on several lines"));
80
81 int defaultLevel = Main.logLevel;
82
83 // Check levels
84 Main.logLevel = 5;
85 assertTrue(Main.isTraceEnabled());
86 assertTrue(Main.isDebugEnabled());
87
88 Main.logLevel = 4;
89 assertFalse(Main.isTraceEnabled());
90 assertTrue(Main.isDebugEnabled());
91
92 Main.logLevel = 3;
93 assertFalse(Main.isTraceEnabled());
94 assertFalse(Main.isDebugEnabled());
95
96 Main.logLevel = defaultLevel;
97 }
98}
Note: See TracBrowser for help on using the repository browser.