| 1 | // License: GPL. For details, see LICENSE file.
|
|---|
| 2 | package org.openstreetmap.josm.data.osm;
|
|---|
| 3 |
|
|---|
| 4 | import static org.junit.Assert.assertEquals;
|
|---|
| 5 | import static org.junit.Assert.assertNull;
|
|---|
| 6 | import static org.junit.Assert.assertTrue;
|
|---|
| 7 |
|
|---|
| 8 | import java.util.Collection;
|
|---|
| 9 |
|
|---|
| 10 | import org.junit.Rule;
|
|---|
| 11 | import org.junit.Test;
|
|---|
| 12 | import org.openstreetmap.josm.TestUtils;
|
|---|
| 13 | import org.openstreetmap.josm.testutils.JOSMTestRules;
|
|---|
| 14 |
|
|---|
| 15 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
|---|
| 16 |
|
|---|
| 17 | /**
|
|---|
| 18 | * Unit tests of the {@code OsmPrimitiveType} class.
|
|---|
| 19 | */
|
|---|
| 20 | public class OsmPrimitiveTypeTest {
|
|---|
| 21 |
|
|---|
| 22 | /**
|
|---|
| 23 | * Setup test.
|
|---|
| 24 | */
|
|---|
| 25 | @Rule
|
|---|
| 26 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
|---|
| 27 | public JOSMTestRules test = new JOSMTestRules();
|
|---|
| 28 |
|
|---|
| 29 | /**
|
|---|
| 30 | * Unit test of {@link OsmPrimitiveType} enum.
|
|---|
| 31 | */
|
|---|
| 32 | @Test
|
|---|
| 33 | public void testEnum() {
|
|---|
| 34 | TestUtils.superficialEnumCodeCoverage(OsmPrimitiveType.class);
|
|---|
| 35 | }
|
|---|
| 36 |
|
|---|
| 37 | /**
|
|---|
| 38 | * Unit test of {@link OsmPrimitiveType#getAPIName} method.
|
|---|
| 39 | */
|
|---|
| 40 | @Test
|
|---|
| 41 | public void testGetApiName() {
|
|---|
| 42 | assertEquals("node", OsmPrimitiveType.NODE.getAPIName());
|
|---|
| 43 | assertEquals("way", OsmPrimitiveType.WAY.getAPIName());
|
|---|
| 44 | assertEquals("relation", OsmPrimitiveType.RELATION.getAPIName());
|
|---|
| 45 | }
|
|---|
| 46 |
|
|---|
| 47 | /**
|
|---|
| 48 | * Unit test of {@link OsmPrimitiveType#getOsmClass} method.
|
|---|
| 49 | */
|
|---|
| 50 | @Test
|
|---|
| 51 | public void testGetOsmClass() {
|
|---|
| 52 | assertEquals(Node.class, OsmPrimitiveType.NODE.getOsmClass());
|
|---|
| 53 | assertEquals(Way.class, OsmPrimitiveType.WAY.getOsmClass());
|
|---|
| 54 | assertEquals(Relation.class, OsmPrimitiveType.RELATION.getOsmClass());
|
|---|
| 55 | assertNull(OsmPrimitiveType.CLOSEDWAY.getOsmClass());
|
|---|
| 56 | assertNull(OsmPrimitiveType.MULTIPOLYGON.getOsmClass());
|
|---|
| 57 | }
|
|---|
| 58 |
|
|---|
| 59 | /**
|
|---|
| 60 | * Unit test of {@link OsmPrimitiveType#getDataClass} method.
|
|---|
| 61 | */
|
|---|
| 62 | @Test
|
|---|
| 63 | public void testGetDataClass() {
|
|---|
| 64 | assertEquals(NodeData.class, OsmPrimitiveType.NODE.getDataClass());
|
|---|
| 65 | assertEquals(WayData.class, OsmPrimitiveType.WAY.getDataClass());
|
|---|
| 66 | assertEquals(RelationData.class, OsmPrimitiveType.RELATION.getDataClass());
|
|---|
| 67 | assertEquals(WayData.class, OsmPrimitiveType.CLOSEDWAY.getDataClass());
|
|---|
| 68 | assertEquals(RelationData.class, OsmPrimitiveType.MULTIPOLYGON.getDataClass());
|
|---|
| 69 | }
|
|---|
| 70 |
|
|---|
| 71 | /**
|
|---|
| 72 | * Unit test of {@link OsmPrimitiveType#fromApiTypeName} method.
|
|---|
| 73 | */
|
|---|
| 74 | @Test
|
|---|
| 75 | public void testFromApiTypeName() {
|
|---|
| 76 | assertEquals(OsmPrimitiveType.NODE, OsmPrimitiveType.fromApiTypeName("node"));
|
|---|
| 77 | assertEquals(OsmPrimitiveType.WAY, OsmPrimitiveType.fromApiTypeName("way"));
|
|---|
| 78 | assertEquals(OsmPrimitiveType.RELATION, OsmPrimitiveType.fromApiTypeName("relation"));
|
|---|
| 79 | }
|
|---|
| 80 |
|
|---|
| 81 | /**
|
|---|
| 82 | * Unit test of {@link OsmPrimitiveType#fromApiTypeName} method - error case.
|
|---|
| 83 | */
|
|---|
| 84 | @Test(expected = IllegalArgumentException.class)
|
|---|
| 85 | public void testFromApiTypeNameError() {
|
|---|
| 86 | OsmPrimitiveType.fromApiTypeName("foo");
|
|---|
| 87 | }
|
|---|
| 88 |
|
|---|
| 89 | /**
|
|---|
| 90 | * Unit test of {@link OsmPrimitiveType#from(IPrimitive)} method.
|
|---|
| 91 | */
|
|---|
| 92 | @Test
|
|---|
| 93 | public void testFromIPrimitive() {
|
|---|
| 94 | assertEquals(OsmPrimitiveType.NODE, OsmPrimitiveType.from(new Node()));
|
|---|
| 95 | assertEquals(OsmPrimitiveType.WAY, OsmPrimitiveType.from(new Way()));
|
|---|
| 96 | assertEquals(OsmPrimitiveType.RELATION, OsmPrimitiveType.from(new Relation()));
|
|---|
| 97 | }
|
|---|
| 98 |
|
|---|
| 99 | /**
|
|---|
| 100 | * Unit test of {@link OsmPrimitiveType#from(IPrimitive)} method - error case.
|
|---|
| 101 | */
|
|---|
| 102 | @Test(expected = IllegalArgumentException.class)
|
|---|
| 103 | public void testFromIPrimitiveError() {
|
|---|
| 104 | OsmPrimitiveType.from((IPrimitive) null);
|
|---|
| 105 | }
|
|---|
| 106 |
|
|---|
| 107 | /**
|
|---|
| 108 | * Unit test of {@link OsmPrimitiveType#from(String)} method.
|
|---|
| 109 | */
|
|---|
| 110 | @Test
|
|---|
| 111 | public void testFromString() {
|
|---|
| 112 | assertEquals(OsmPrimitiveType.NODE, OsmPrimitiveType.from("node"));
|
|---|
| 113 | assertEquals(OsmPrimitiveType.WAY, OsmPrimitiveType.from("WAY"));
|
|---|
| 114 | assertEquals(OsmPrimitiveType.RELATION, OsmPrimitiveType.from("Relation"));
|
|---|
| 115 | assertEquals(OsmPrimitiveType.CLOSEDWAY, OsmPrimitiveType.from("closedway"));
|
|---|
| 116 | assertEquals(OsmPrimitiveType.MULTIPOLYGON, OsmPrimitiveType.from("multipolygon"));
|
|---|
| 117 | assertNull(OsmPrimitiveType.from((String) null));
|
|---|
| 118 | }
|
|---|
| 119 |
|
|---|
| 120 | /**
|
|---|
| 121 | * Unit test of {@link OsmPrimitiveType#dataValues} method.
|
|---|
| 122 | */
|
|---|
| 123 | @Test
|
|---|
| 124 | public void testDataValues() {
|
|---|
| 125 | Collection<OsmPrimitiveType> values = OsmPrimitiveType.dataValues();
|
|---|
| 126 | assertEquals(3, values.size());
|
|---|
| 127 | assertTrue(values.contains(OsmPrimitiveType.NODE));
|
|---|
| 128 | assertTrue(values.contains(OsmPrimitiveType.WAY));
|
|---|
| 129 | assertTrue(values.contains(OsmPrimitiveType.RELATION));
|
|---|
| 130 | }
|
|---|
| 131 |
|
|---|
| 132 | /**
|
|---|
| 133 | * Unit test of {@link OsmPrimitiveType#newInstance} method.
|
|---|
| 134 | */
|
|---|
| 135 | @Test
|
|---|
| 136 | public void testNewInstance() {
|
|---|
| 137 | OsmPrimitive n = OsmPrimitiveType.NODE.newInstance(1, false);
|
|---|
| 138 | OsmPrimitive w = OsmPrimitiveType.WAY.newInstance(2, false);
|
|---|
| 139 | OsmPrimitive r = OsmPrimitiveType.RELATION.newInstance(3, false);
|
|---|
| 140 |
|
|---|
| 141 | assertTrue(n instanceof Node);
|
|---|
| 142 | assertTrue(w instanceof Way);
|
|---|
| 143 | assertTrue(r instanceof Relation);
|
|---|
| 144 |
|
|---|
| 145 | assertEquals(1, n.getId());
|
|---|
| 146 | assertEquals(2, w.getId());
|
|---|
| 147 | assertEquals(3, r.getId());
|
|---|
| 148 | }
|
|---|
| 149 |
|
|---|
| 150 | /**
|
|---|
| 151 | * Unit test of {@link OsmPrimitiveType#newInstance} method - error case.
|
|---|
| 152 | */
|
|---|
| 153 | @Test(expected = AssertionError.class)
|
|---|
| 154 | public void testNewInstanceError() {
|
|---|
| 155 | OsmPrimitiveType.CLOSEDWAY.newInstance(1, false);
|
|---|
| 156 | }
|
|---|
| 157 |
|
|---|
| 158 | /**
|
|---|
| 159 | * Unit test of {@link OsmPrimitiveType#newVersionedInstance} method.
|
|---|
| 160 | */
|
|---|
| 161 | @Test
|
|---|
| 162 | public void testNewVersionedInstance() {
|
|---|
| 163 | OsmPrimitive n = OsmPrimitiveType.NODE.newVersionedInstance(1, 4);
|
|---|
| 164 | OsmPrimitive w = OsmPrimitiveType.WAY.newVersionedInstance(2, 5);
|
|---|
| 165 | OsmPrimitive r = OsmPrimitiveType.RELATION.newVersionedInstance(3, 6);
|
|---|
| 166 |
|
|---|
| 167 | assertTrue(n instanceof Node);
|
|---|
| 168 | assertTrue(w instanceof Way);
|
|---|
| 169 | assertTrue(r instanceof Relation);
|
|---|
| 170 |
|
|---|
| 171 | assertEquals(1, n.getId());
|
|---|
| 172 | assertEquals(2, w.getId());
|
|---|
| 173 | assertEquals(3, r.getId());
|
|---|
| 174 |
|
|---|
| 175 | assertEquals(4, n.getVersion());
|
|---|
| 176 | assertEquals(5, w.getVersion());
|
|---|
| 177 | assertEquals(6, r.getVersion());
|
|---|
| 178 | }
|
|---|
| 179 |
|
|---|
| 180 | /**
|
|---|
| 181 | * Unit test of {@link OsmPrimitiveType#newVersionedInstance} method - error case.
|
|---|
| 182 | */
|
|---|
| 183 | @Test(expected = AssertionError.class)
|
|---|
| 184 | public void testNewVersionedInstanceError() {
|
|---|
| 185 | OsmPrimitiveType.CLOSEDWAY.newVersionedInstance(1, 0);
|
|---|
| 186 | }
|
|---|
| 187 | }
|
|---|