[8799] | 1 | // License: GPL. For details, see LICENSE file.
|
---|
| 2 | package org.openstreetmap.josm;
|
---|
| 3 |
|
---|
[8857] | 4 | import static org.junit.Assert.assertEquals;
|
---|
[10962] | 5 | import static org.junit.Assert.assertNotNull;
|
---|
[8857] | 6 | import static org.junit.Assert.assertNull;
|
---|
| 7 | import static org.junit.Assert.assertTrue;
|
---|
[8799] | 8 |
|
---|
[8857] | 9 | import java.util.Collection;
|
---|
| 10 |
|
---|
[10962] | 11 | import javax.swing.UIManager;
|
---|
| 12 |
|
---|
[10966] | 13 | import org.junit.Rule;
|
---|
[8799] | 14 | import org.junit.Test;
|
---|
[8857] | 15 | import org.openstreetmap.josm.Main.DownloadParamType;
|
---|
[10966] | 16 | import org.openstreetmap.josm.testutils.JOSMTestRules;
|
---|
[8799] | 17 |
|
---|
[10222] | 18 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
---|
| 19 |
|
---|
[8857] | 20 | /**
|
---|
| 21 | * Unit tests of {@link Main} class.
|
---|
| 22 | */
|
---|
[8799] | 23 | public class MainTest {
|
---|
[8857] | 24 |
|
---|
| 25 | /**
|
---|
[10200] | 26 | * Setup test.
|
---|
| 27 | */
|
---|
[10966] | 28 | @Rule
|
---|
| 29 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
---|
| 30 | public JOSMTestRules test = new JOSMTestRules().platform();
|
---|
[10200] | 31 |
|
---|
| 32 | /**
|
---|
[8857] | 33 | * Unit test of {@link DownloadParamType#paramType} method.
|
---|
| 34 | */
|
---|
[8799] | 35 | @Test
|
---|
[8857] | 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"));
|
---|
[8799] | 43 | }
|
---|
[8857] | 44 |
|
---|
| 45 | /**
|
---|
| 46 | * Unit tests on log messages.
|
---|
| 47 | */
|
---|
| 48 | @Test
|
---|
[10222] | 49 | @SuppressFBWarnings(value = "ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD")
|
---|
[8857] | 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 | }
|
---|
[10962] | 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 | }
|
---|
[8799] | 83 | }
|
---|