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