1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.actions;
|
---|
3 |
|
---|
4 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
---|
5 | import static org.junit.jupiter.api.Assertions.assertNull;
|
---|
6 | import static org.junit.jupiter.api.Assertions.assertThrows;
|
---|
7 |
|
---|
8 | import java.util.Arrays;
|
---|
9 | import java.util.Collections;
|
---|
10 |
|
---|
11 | import org.junit.jupiter.api.Test;
|
---|
12 | import org.junit.jupiter.api.extension.RegisterExtension;
|
---|
13 | import org.openstreetmap.josm.data.coor.LatLon;
|
---|
14 | import org.openstreetmap.josm.data.osm.DataSet;
|
---|
15 | import org.openstreetmap.josm.data.osm.Node;
|
---|
16 | import org.openstreetmap.josm.spi.preferences.Config;
|
---|
17 | import org.openstreetmap.josm.testutils.JOSMTestRules;
|
---|
18 |
|
---|
19 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
---|
20 |
|
---|
21 | /**
|
---|
22 | * Unit tests for class {@link MergeNodesAction}.
|
---|
23 | */
|
---|
24 | class MergeNodesActionTest {
|
---|
25 |
|
---|
26 | /**
|
---|
27 | * Setup test.
|
---|
28 | */
|
---|
29 | @RegisterExtension
|
---|
30 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
---|
31 | public JOSMTestRules test = new JOSMTestRules().projection();
|
---|
32 |
|
---|
33 | /**
|
---|
34 | * Unit test of {@link MergeNodesAction#selectTargetLocationNode} - empty list
|
---|
35 | */
|
---|
36 | @Test
|
---|
37 | void testSelectTargetLocationNodeEmpty() {
|
---|
38 | assertThrows(IllegalArgumentException.class, () -> MergeNodesAction.selectTargetLocationNode(Collections.emptyList()));
|
---|
39 | }
|
---|
40 |
|
---|
41 | /**
|
---|
42 | * Unit test of {@link MergeNodesAction#selectTargetLocationNode} - invalid mode
|
---|
43 | */
|
---|
44 | @Test
|
---|
45 | void testSelectTargetLocationNodeInvalidMode() {
|
---|
46 | Config.getPref().putInt("merge-nodes.mode", -1);
|
---|
47 | assertThrows(IllegalStateException.class, () -> MergeNodesAction.selectTargetLocationNode(Arrays.asList(new Node(0), new Node(1))));
|
---|
48 | }
|
---|
49 |
|
---|
50 | /**
|
---|
51 | * Unit test of {@link MergeNodesAction#selectTargetLocationNode}
|
---|
52 | */
|
---|
53 | @Test
|
---|
54 | void testSelectTargetLocationNode() {
|
---|
55 | Config.getPref().putInt("merge-nodes.mode", 0);
|
---|
56 | assertEquals(1, MergeNodesAction.selectTargetLocationNode(Arrays.asList(new Node(0), new Node(1))).getId());
|
---|
57 |
|
---|
58 | Config.getPref().putInt("merge-nodes.mode", 1);
|
---|
59 | assertEquals(LatLon.ZERO, MergeNodesAction.selectTargetLocationNode(
|
---|
60 | Arrays.asList(new Node(LatLon.NORTH_POLE), new Node(LatLon.SOUTH_POLE))).getCoor());
|
---|
61 |
|
---|
62 | Config.getPref().putInt("merge-nodes.mode", 2);
|
---|
63 | assertEquals(LatLon.NORTH_POLE, MergeNodesAction.selectTargetLocationNode(
|
---|
64 | Arrays.asList(new Node(LatLon.NORTH_POLE))).getCoor());
|
---|
65 | }
|
---|
66 |
|
---|
67 | /**
|
---|
68 | * Unit test of {@link MergeNodesAction#selectTargetNode}
|
---|
69 | */
|
---|
70 | @Test
|
---|
71 | void testSelectTargetNode() {
|
---|
72 | assertNull(MergeNodesAction.selectTargetNode(Collections.emptyList()));
|
---|
73 | DataSet ds = new DataSet();
|
---|
74 | Node n1 = new Node(1);
|
---|
75 | ds.addPrimitive(n1);
|
---|
76 | assertEquals(1, MergeNodesAction.selectTargetNode(Arrays.asList(n1)).getId());
|
---|
77 | }
|
---|
78 | }
|
---|