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

Last change on this file was 18853, checked in by taylor.smock, 7 months ago

See #16567: Update to JUnit 5

This removes new JOSMTestRules() with no additional setup and most
JOSMFixture calls.

Removing the bare JOSMTestRules speeds up the test suite since there are two
fewer System.gc() calls per test.

  • Property svn:eol-style set to native
File size: 2.9 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.assertInstanceOf;
7import static org.junit.jupiter.api.Assertions.assertNull;
8import static org.junit.jupiter.api.Assertions.assertThrows;
9import static org.junit.jupiter.api.Assertions.assertTrue;
10
11import java.util.Arrays;
12import java.util.stream.Collectors;
13
14import org.junit.jupiter.api.Test;
15
16/**
17 * Unit tests for class {@link OsmUtils}.
18 */
19class OsmUtilsTest {
20 /**
21 * Unit test of {@link OsmUtils#createPrimitive}
22 */
23 @Test
24 void testCreatePrimitive() {
25 final OsmPrimitive p = OsmUtils.createPrimitive("way name=Foo railway=rail");
26 assertInstanceOf(Way.class, p);
27 assertEquals(2, p.getKeys().size());
28 assertEquals("Foo", p.get("name"));
29 assertEquals("rail", p.get("railway"));
30 }
31
32 /**
33 * Unit test of {@link OsmUtils#createPrimitive}
34 */
35 @Test
36 void testArea() {
37 final OsmPrimitive p = OsmUtils.createPrimitive("area name=Foo railway=rail");
38 assertEquals(OsmPrimitiveType.WAY, p.getType());
39 assertEquals(p.getKeys(), OsmUtils.createPrimitive("way name=Foo railway=rail").getKeys());
40 }
41
42 /**
43 * Unit test of {@link OsmUtils#createPrimitive}
44 */
45 @Test
46 void testCreatePrimitiveFail() {
47 assertThrows(IllegalArgumentException.class, () -> OsmUtils.createPrimitive("noway name=Foo"));
48 }
49
50 /**
51 * Unit test of {@link OsmUtils#splitMultipleValues}
52 */
53 @Test
54 void testSplitMultipleValues() {
55 // examples from https://wiki.openstreetmap.org/wiki/Semi-colon_value_separator
56 assertEquals(Arrays.asList("B500", "B550"), OsmUtils.splitMultipleValues("B500;B550").collect(Collectors.toList()));
57 assertEquals(Arrays.asList("B500", "B550"), OsmUtils.splitMultipleValues("B500 ; B550").collect(Collectors.toList()));
58 assertEquals(Arrays.asList("Tu-Fr 08:00-18:00", "Mo 09:00-18:00", "Sa 09:00-12:00", "closed Aug"),
59 OsmUtils.splitMultipleValues("Tu-Fr 08:00-18:00;Mo 09:00-18:00;Sa 09:00-12:00;closed Aug").collect(Collectors.toList()));
60 }
61
62 /**
63 * Unit test of {@link OsmUtils#isTrue}, {@link OsmUtils#isFalse}, {@link OsmUtils#getOsmBoolean}
64 */
65 @Test
66 void testTrueFalse() {
67 assertFalse(OsmUtils.isTrue(null));
68 assertFalse(OsmUtils.isFalse(null));
69 assertNull(OsmUtils.getOsmBoolean(null));
70 assertTrue(OsmUtils.isTrue("yes"));
71 assertFalse(OsmUtils.isFalse("yes"));
72 assertEquals(Boolean.TRUE, OsmUtils.getOsmBoolean("yes"));
73 assertTrue(OsmUtils.isFalse("no"));
74 assertFalse(OsmUtils.isTrue("no"));
75 assertEquals(Boolean.FALSE, OsmUtils.getOsmBoolean("no"));
76 assertNull(OsmUtils.getOsmBoolean("foobar"));
77 }
78}
Note: See TracBrowser for help on using the repository browser.