source: josm/trunk/test/unit/org/openstreetmap/josm/data/osm/OsmUtilsTest.java@ 17275

Last change on this file since 17275 was 17275, checked in by Don-vip, 3 years ago

see #16567 - upgrade almost all tests to JUnit 5, except those depending on WiremockRule

See https://github.com/tomakehurst/wiremock/issues/684

  • Property svn:eol-style set to native
File size: 3.2 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.osm;
3
4import static org.junit.jupiter.api.Assertions.assertEquals;
5import static org.junit.jupiter.api.Assertions.assertFalse;
6import static org.junit.jupiter.api.Assertions.assertNull;
7import static org.junit.jupiter.api.Assertions.assertTrue;
8import static org.junit.jupiter.api.Assertions.assertThrows;
9
10import java.util.Arrays;
11import java.util.stream.Collectors;
12
13import org.junit.jupiter.api.Test;
14import org.junit.jupiter.api.extension.RegisterExtension;
15import org.openstreetmap.josm.testutils.JOSMTestRules;
16
17import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
18
19/**
20 * Unit tests for class {@link OsmUtils}.
21 */
22class 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}
Note: See TracBrowser for help on using the repository browser.