source: josm/trunk/test/unit/org/openstreetmap/josm/actions/MergeNodesActionTest.java@ 17275

Last change on this file since 17275 was 17275, checked in by Don-vip, 3 years ago

see #16567 - upgrade almost all tests to JUnit 5, except those depending on WiremockRule

See https://github.com/tomakehurst/wiremock/issues/684

  • Property svn:eol-style set to native
File size: 2.8 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.actions;
3
4import static org.junit.jupiter.api.Assertions.assertEquals;
5import static org.junit.jupiter.api.Assertions.assertNull;
6import static org.junit.jupiter.api.Assertions.assertThrows;
7
8import java.util.Arrays;
9import java.util.Collections;
10
11import org.junit.jupiter.api.Test;
12import org.junit.jupiter.api.extension.RegisterExtension;
13import org.openstreetmap.josm.data.coor.LatLon;
14import org.openstreetmap.josm.data.osm.DataSet;
15import org.openstreetmap.josm.data.osm.Node;
16import org.openstreetmap.josm.spi.preferences.Config;
17import org.openstreetmap.josm.testutils.JOSMTestRules;
18
19import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
20
21/**
22 * Unit tests for class {@link MergeNodesAction}.
23 */
24class 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}
Note: See TracBrowser for help on using the repository browser.