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.BeforeClass;
|
---|
13 | import org.junit.Test;
|
---|
14 | import org.openstreetmap.josm.JOSMFixture;
|
---|
15 | import org.openstreetmap.josm.TestUtils;
|
---|
16 | import org.openstreetmap.josm.actions.CombineWayAction.NodeGraph;
|
---|
17 | import org.openstreetmap.josm.actions.CombineWayAction.NodePair;
|
---|
18 | import org.openstreetmap.josm.data.osm.DataSet;
|
---|
19 | import org.openstreetmap.josm.data.osm.Node;
|
---|
20 | import org.openstreetmap.josm.io.IllegalDataException;
|
---|
21 | import org.openstreetmap.josm.io.OsmReader;
|
---|
22 |
|
---|
23 | import nl.jqno.equalsverifier.EqualsVerifier;
|
---|
24 |
|
---|
25 | /**
|
---|
26 | * Unit tests for class {@link CombineWayAction}.
|
---|
27 | */
|
---|
28 | public class CombineWayActionTest {
|
---|
29 |
|
---|
30 | /**
|
---|
31 | * Setup test.
|
---|
32 | */
|
---|
33 | @BeforeClass
|
---|
34 | public static void setUp() {
|
---|
35 | JOSMFixture.createUnitTestFixture().init();
|
---|
36 | }
|
---|
37 |
|
---|
38 | /**
|
---|
39 | * Non-regression test for bug #11957.
|
---|
40 | * @throws IOException if any I/O error occurs
|
---|
41 | * @throws IllegalDataException if OSM parsing fails
|
---|
42 | */
|
---|
43 | @Test
|
---|
44 | public void testTicket11957() throws IOException, IllegalDataException {
|
---|
45 | try (InputStream is = TestUtils.getRegressionDataStream(11957, "data.osm")) {
|
---|
46 | DataSet ds = OsmReader.parseDataSet(is, null);
|
---|
47 | NodeGraph graph = NodeGraph.createNearlyUndirectedGraphFromNodeWays(ds.getWays());
|
---|
48 | List<Node> path = graph.buildSpanningPath();
|
---|
49 | assertEquals(10, path.size());
|
---|
50 | Set<Long> firstAndLastObtained = new HashSet<>();
|
---|
51 | firstAndLastObtained.add(path.get(0).getId());
|
---|
52 | firstAndLastObtained.add(path.get(path.size()-1).getId());
|
---|
53 | Set<Long> firstAndLastExpected = new HashSet<>();
|
---|
54 | firstAndLastExpected.add(1618969016L);
|
---|
55 | firstAndLastExpected.add(35213705L);
|
---|
56 | assertEquals(firstAndLastExpected, firstAndLastObtained);
|
---|
57 | }
|
---|
58 | }
|
---|
59 |
|
---|
60 | /**
|
---|
61 | * Unit test of methods {@link NodePair#equals} and {@link NodePair#hashCode}.
|
---|
62 | */
|
---|
63 | @Test
|
---|
64 | public void testEqualsContract() {
|
---|
65 | EqualsVerifier.forClass(NodePair.class).usingGetClass()
|
---|
66 | .withPrefabValues(Node.class, new Node(1), new Node(2))
|
---|
67 | .verify();
|
---|
68 | }
|
---|
69 | }
|
---|