1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.actions;
|
---|
3 |
|
---|
4 | import static org.junit.Assert.assertEquals;
|
---|
5 |
|
---|
6 | import java.io.IOException;
|
---|
7 | import java.io.InputStream;
|
---|
8 | import java.util.HashSet;
|
---|
9 | import java.util.List;
|
---|
10 | import java.util.Set;
|
---|
11 |
|
---|
12 | import org.junit.Rule;
|
---|
13 | import org.junit.Test;
|
---|
14 | import org.openstreetmap.josm.TestUtils;
|
---|
15 | import org.openstreetmap.josm.actions.CombineWayAction.NodeGraph;
|
---|
16 | import org.openstreetmap.josm.actions.CombineWayAction.NodePair;
|
---|
17 | import org.openstreetmap.josm.data.osm.DataSet;
|
---|
18 | import org.openstreetmap.josm.data.osm.Node;
|
---|
19 | import org.openstreetmap.josm.io.IllegalDataException;
|
---|
20 | import org.openstreetmap.josm.io.OsmReader;
|
---|
21 | import org.openstreetmap.josm.testutils.JOSMTestRules;
|
---|
22 |
|
---|
23 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
---|
24 | import nl.jqno.equalsverifier.EqualsVerifier;
|
---|
25 | import nl.jqno.equalsverifier.Warning;
|
---|
26 |
|
---|
27 | /**
|
---|
28 | * Unit tests for class {@link CombineWayAction}.
|
---|
29 | */
|
---|
30 | public class CombineWayActionTest {
|
---|
31 |
|
---|
32 | /**
|
---|
33 | * Setup test.
|
---|
34 | */
|
---|
35 | @Rule
|
---|
36 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
---|
37 | public JOSMTestRules test = new JOSMTestRules();
|
---|
38 |
|
---|
39 | /**
|
---|
40 | * Non-regression test for bug #11957.
|
---|
41 | * @throws IOException if any I/O error occurs
|
---|
42 | * @throws IllegalDataException if OSM parsing fails
|
---|
43 | */
|
---|
44 | @Test
|
---|
45 | public void testTicket11957() throws IOException, IllegalDataException {
|
---|
46 | try (InputStream is = TestUtils.getRegressionDataStream(11957, "data.osm")) {
|
---|
47 | DataSet ds = OsmReader.parseDataSet(is, null);
|
---|
48 | NodeGraph graph = NodeGraph.createNearlyUndirectedGraphFromNodeWays(ds.getWays());
|
---|
49 | List<Node> path = graph.buildSpanningPath();
|
---|
50 | assertEquals(10, path.size());
|
---|
51 | Set<Long> firstAndLastObtained = new HashSet<>();
|
---|
52 | firstAndLastObtained.add(path.get(0).getId());
|
---|
53 | firstAndLastObtained.add(path.get(path.size()-1).getId());
|
---|
54 | Set<Long> firstAndLastExpected = new HashSet<>();
|
---|
55 | firstAndLastExpected.add(1618969016L);
|
---|
56 | firstAndLastExpected.add(35213705L);
|
---|
57 | assertEquals(firstAndLastExpected, firstAndLastObtained);
|
---|
58 | }
|
---|
59 | }
|
---|
60 |
|
---|
61 | /**
|
---|
62 | * Unit test of methods {@link NodePair#equals} and {@link NodePair#hashCode}.
|
---|
63 | */
|
---|
64 | @Test
|
---|
65 | public void testEqualsContract() {
|
---|
66 | EqualsVerifier.forClass(NodePair.class).usingGetClass()
|
---|
67 | .suppress(Warning.ANNOTATION) // FIXME: remove it after https://github.com/jqno/equalsverifier/issues/152 is fixed
|
---|
68 | .withPrefabValues(Node.class, new Node(1), new Node(2))
|
---|
69 | .verify();
|
---|
70 | }
|
---|
71 | }
|
---|