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

Last change on this file since 9384 was 8857, checked in by Don-vip, 9 years ago

improve/cleanup unit tests

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