source: josm/trunk/test/unit/org/openstreetmap/josm/actions/SplitWayActionTest.java@ 18690

Last change on this file since 18690 was 18690, checked in by taylor.smock, 13 months ago

See #16567: Convert all assertion calls to JUnit 5 (patch by gaben, modified)

The modifications are as follows:

  • Merge DomainValidatorTest.testIDN and DomainValidatorTest.testIDNJava6OrLater
  • Update some tests to use @ParameterizedTest (DomainValidatorTest)
  • Replace various exception blocks with assertThrows. These typically looked like
        try {
            // Something that should throw an exception here
            fail("An exception should have been thrown");
        } catch (Exception e) {
            // Verify the exception matches expectations here
        }
    
  • Replace assertTrue(val instanceof Clazz) with assertInstanceOf
  • Replace JUnit 4 @Suite with JUnit 5 @Suite

Both the original patch and the modified patch fix various lint issues.

  • Property svn:eol-style set to native
File size: 4.8 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.actions;
3
4import static org.junit.jupiter.api.Assertions.assertSame;
5import static org.junit.jupiter.api.Assertions.assertTrue;
6
7import java.util.Arrays;
8
9import org.junit.jupiter.api.Test;
10import org.junit.jupiter.api.extension.RegisterExtension;
11import org.openstreetmap.josm.TestUtils;
12import org.openstreetmap.josm.data.coor.EastNorth;
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.data.osm.Relation;
17import org.openstreetmap.josm.data.osm.RelationMember;
18import org.openstreetmap.josm.data.osm.Way;
19import org.openstreetmap.josm.testutils.JOSMTestRules;
20
21import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
22
23/**
24 * Unit tests for class {@link SplitWayAction}.
25 */
26final class SplitWayActionTest {
27
28 /**
29 * Setup test.
30 */
31 @RegisterExtension
32 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
33 public JOSMTestRules test = new JOSMTestRules().projection();
34 private final DataSet dataSet = new DataSet();
35
36 private Node addNode(int east, int north) {
37 final Node node = new Node(new EastNorth(east, north));
38 dataSet.addPrimitive(node);
39 return node;
40 }
41
42 /**
43 * Test case: When node is share by multiple ways, split selected way.
44 * see #11184
45 */
46 @Test
47 void testTicket11184() {
48 Node n1 = addNode(0, 0);
49 Node n2 = addNode(-1, 1);
50 Node n3 = addNode(1, 1);
51 Node n4 = addNode(-1, -1);
52 Node n5 = addNode(1, -1);
53 Node n6 = addNode(-1, 0);
54 Node n7 = addNode(1, 0);
55
56 Way w1 = new Way();
57 Node[] w1NodesArray = new Node[] {n6, n1, n7};
58 w1.setNodes(Arrays.asList(w1NodesArray));
59 Way w2 = new Way();
60 w2.setNodes(Arrays.asList(n1, n2, n3, n1, n4, n5, n1));
61 dataSet.addPrimitive(w1);
62 dataSet.addPrimitive(w2);
63
64 dataSet.addSelected(n1);
65 dataSet.addSelected(w2);
66
67 SplitWayAction.runOn(dataSet);
68
69 // Ensures 3 ways.
70 assertSame(3, dataSet.getWays().size(), String.format("Found %d ways after split action instead of 3.", dataSet.getWays().size()));
71
72 // Ensures way w1 is unchanged.
73 assertTrue(dataSet.getWays().contains(w1), "Unselected ways disappear during split action.");
74 assertSame(3, w1.getNodesCount(), "Unselected way seems to have change during split action.");
75 for (int i = 0; i < 3; i++) {
76 assertSame(w1.getNode(i), w1NodesArray[i], "Node change in unselected way during split action.");
77 }
78 }
79
80 /**
81 * Test case: when a way is split with a turn restriction relation,
82 * the relation should not be broken.
83 * see #17810
84 */
85 @Test
86 void testTicket17810() {
87 DataSet dataSet = new DataSet();
88 Way from = TestUtils.newWay("highway=residential", new Node(new LatLon(0.0, 0.0)),
89 new Node(new LatLon(0.00033, 0.00033)), new Node(new LatLon(0.00066, 0.00066)),
90 new Node(new LatLon(0.001, 0.001)));
91 from.getNodes().forEach(dataSet::addPrimitive);
92 dataSet.addPrimitive(from);
93 Node via = from.lastNode();
94 Way to = TestUtils.newWay("highway=residential", new Node(new LatLon(0.002, 0.001)), via);
95 to.getNodes().forEach(node -> {
96 if (!dataSet.containsNode(node)) {
97 dataSet.addPrimitive(node);
98 }
99 });
100 dataSet.addPrimitive(to);
101 Relation restriction = TestUtils.newRelation("type=restriction restriction=no_left_turn",
102 new RelationMember("from", from), new RelationMember("to", to),
103 new RelationMember("via", via));
104 dataSet.addPrimitive(restriction);
105 dataSet.clearSelection();
106 dataSet.addSelected(from.getNode(2), from);
107 SplitWayAction.runOn(dataSet);
108 for (RelationMember member : restriction.getMembers()) {
109 if ("from".equals(member.getRole())) {
110 assertTrue(member.getWay().containsNode(via));
111 }
112 }
113 }
114
115 /**
116 * Test case: smart way selection
117 * see #18477
118 */
119 @Test
120 void testTicket18477() {
121 final Node n10 = addNode(1, 0);
122 final Node n21 = addNode(2, 1);
123 final Way highway = TestUtils.newWay("highway=residential",
124 addNode(0, 0), n10, n21, addNode(3, 1));
125 final Way bridge = TestUtils.newWay("man_made=bridge",
126 n10, addNode(2, 0), n21, addNode(1, 1), n10);
127 dataSet.addPrimitive(highway);
128 dataSet.addPrimitive(bridge);
129 dataSet.setSelected(n10, n21);
130 SplitWayAction.runOn(dataSet);
131 assertSame(4, dataSet.getWays().size(), String.format("Found %d ways after split action instead of 4.", dataSet.getWays().size()));
132 }
133}
Note: See TracBrowser for help on using the repository browser.