1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.data.osm;
|
---|
3 |
|
---|
4 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
---|
5 | import static org.junit.jupiter.api.Assertions.assertFalse;
|
---|
6 | import static org.junit.jupiter.api.Assertions.assertNull;
|
---|
7 | import static org.junit.jupiter.api.Assertions.assertTrue;
|
---|
8 | import static org.junit.jupiter.api.Assertions.assertThrows;
|
---|
9 |
|
---|
10 | import java.util.Arrays;
|
---|
11 | import java.util.stream.Collectors;
|
---|
12 |
|
---|
13 | import org.junit.jupiter.api.Test;
|
---|
14 | import org.junit.jupiter.api.extension.RegisterExtension;
|
---|
15 | import org.openstreetmap.josm.testutils.JOSMTestRules;
|
---|
16 |
|
---|
17 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
---|
18 |
|
---|
19 | /**
|
---|
20 | * Unit tests for class {@link OsmUtils}.
|
---|
21 | */
|
---|
22 | class OsmUtilsTest {
|
---|
23 |
|
---|
24 | /**
|
---|
25 | * Setup test.
|
---|
26 | */
|
---|
27 | @RegisterExtension
|
---|
28 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
---|
29 | public JOSMTestRules test = new JOSMTestRules();
|
---|
30 |
|
---|
31 | /**
|
---|
32 | * Unit test of {@link OsmUtils#createPrimitive}
|
---|
33 | */
|
---|
34 | @Test
|
---|
35 | void testCreatePrimitive() {
|
---|
36 | final OsmPrimitive p = OsmUtils.createPrimitive("way name=Foo railway=rail");
|
---|
37 | assertTrue(p instanceof Way);
|
---|
38 | assertEquals(2, p.keySet().size());
|
---|
39 | assertEquals("Foo", p.get("name"));
|
---|
40 | assertEquals("rail", p.get("railway"));
|
---|
41 | }
|
---|
42 |
|
---|
43 | /**
|
---|
44 | * Unit test of {@link OsmUtils#createPrimitive}
|
---|
45 | */
|
---|
46 | @Test
|
---|
47 | void testArea() {
|
---|
48 | final OsmPrimitive p = OsmUtils.createPrimitive("area name=Foo railway=rail");
|
---|
49 | assertEquals(OsmPrimitiveType.WAY, p.getType());
|
---|
50 | assertEquals(p.getKeys(), OsmUtils.createPrimitive("way name=Foo railway=rail").getKeys());
|
---|
51 | }
|
---|
52 |
|
---|
53 | /**
|
---|
54 | * Unit test of {@link OsmUtils#createPrimitive}
|
---|
55 | */
|
---|
56 | @Test
|
---|
57 | void testCreatePrimitiveFail() {
|
---|
58 | assertThrows(IllegalArgumentException.class, () -> OsmUtils.createPrimitive("noway name=Foo"));
|
---|
59 | }
|
---|
60 |
|
---|
61 | /**
|
---|
62 | * Unit test of {@link OsmUtils#splitMultipleValues}
|
---|
63 | */
|
---|
64 | @Test
|
---|
65 | void testSplitMultipleValues() {
|
---|
66 | // examples from https://wiki.openstreetmap.org/wiki/Semi-colon_value_separator
|
---|
67 | assertEquals(Arrays.asList("B500", "B550"), OsmUtils.splitMultipleValues("B500;B550").collect(Collectors.toList()));
|
---|
68 | assertEquals(Arrays.asList("B500", "B550"), OsmUtils.splitMultipleValues("B500 ; B550").collect(Collectors.toList()));
|
---|
69 | assertEquals(Arrays.asList("Tu-Fr 08:00-18:00", "Mo 09:00-18:00", "Sa 09:00-12:00", "closed Aug"),
|
---|
70 | OsmUtils.splitMultipleValues("Tu-Fr 08:00-18:00;Mo 09:00-18:00;Sa 09:00-12:00;closed Aug").collect(Collectors.toList()));
|
---|
71 | }
|
---|
72 |
|
---|
73 | /**
|
---|
74 | * Unit test of {@link OsmUtils#isTrue}, {@link OsmUtils#isFalse}, {@link OsmUtils#getOsmBoolean}
|
---|
75 | */
|
---|
76 | @Test
|
---|
77 | void testTrueFalse() {
|
---|
78 | assertFalse(OsmUtils.isTrue(null));
|
---|
79 | assertFalse(OsmUtils.isFalse(null));
|
---|
80 | assertNull(OsmUtils.getOsmBoolean(null));
|
---|
81 | assertTrue(OsmUtils.isTrue("yes"));
|
---|
82 | assertFalse(OsmUtils.isFalse("yes"));
|
---|
83 | assertEquals(Boolean.TRUE, OsmUtils.getOsmBoolean("yes"));
|
---|
84 | assertTrue(OsmUtils.isFalse("no"));
|
---|
85 | assertFalse(OsmUtils.isTrue("no"));
|
---|
86 | assertEquals(Boolean.FALSE, OsmUtils.getOsmBoolean("no"));
|
---|
87 | assertNull(OsmUtils.getOsmBoolean("foobar"));
|
---|
88 | }
|
---|
89 | }
|
---|