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

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

fix #13318 - Clean up program startup (parameters, logging) - patch by michael2402 - gsoc-core

File size: 2.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.assertNull;
6import static org.junit.Assert.assertTrue;
7
8import java.util.Collection;
9
10import org.junit.BeforeClass;
11import org.junit.Test;
12import org.openstreetmap.josm.Main.DownloadParamType;
13
14import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
15
16/**
17 * Unit tests of {@link Main} class.
18 */
19public class MainTest {
20
21 /**
22 * Setup test.
23 */
24 @BeforeClass
25 public static void setUp() {
26 JOSMFixture.createUnitTestFixture().init();
27 }
28
29 /**
30 * Unit test of {@link DownloadParamType#paramType} method.
31 */
32 @Test
33 public void testParamType() {
34 assertEquals(DownloadParamType.bounds, DownloadParamType.paramType("48.000,16.000,48.001,16.001"));
35 assertEquals(DownloadParamType.fileName, DownloadParamType.paramType("data.osm"));
36 assertEquals(DownloadParamType.fileUrl, DownloadParamType.paramType("file:///home/foo/data.osm"));
37 assertEquals(DownloadParamType.fileUrl, DownloadParamType.paramType("file://C:\\Users\\foo\\data.osm"));
38 assertEquals(DownloadParamType.httpUrl, DownloadParamType.paramType("http://somewhere.com/data.osm"));
39 assertEquals(DownloadParamType.httpUrl, DownloadParamType.paramType("https://somewhere.com/data.osm"));
40 }
41
42 /**
43 * Unit tests on log messages.
44 */
45 @Test
46 @SuppressFBWarnings(value = "ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD")
47 public void testLogs() {
48
49 assertNull(Main.getErrorMessage(null));
50
51 // Correct behaviour with errors
52 Main.error(new Exception("exception_error"));
53 Main.error("Error message on one line");
54 Main.error("First line of error message on several lines\nline2\nline3\nline4");
55 Collection<String> errors = Main.getLastErrorAndWarnings();
56 assertTrue(errors.contains("E: java.lang.Exception: exception_error"));
57 assertTrue(errors.contains("E: Error message on one line"));
58 assertTrue(errors.contains("E: First line of error message on several lines"));
59
60 // Correct behaviour with warnings
61 Main.warn(new Exception("exception_warn", new Exception("root_cause")));
62 Main.warn("Warning message on one line");
63 Main.warn("First line of warning message on several lines\nline2\nline3\nline4");
64 Collection<String> warnings = Main.getLastErrorAndWarnings();
65 assertTrue(warnings.contains("W: java.lang.Exception: exception_warn. Cause: java.lang.Exception: root_cause"));
66 assertTrue(warnings.contains("W: Warning message on one line"));
67 assertTrue(warnings.contains("W: First line of warning message on several lines"));
68 }
69}
Note: See TracBrowser for help on using the repository browser.