Changeset 12828 in josm for trunk/test/unit/org/openstreetmap
- Timestamp:
- 2017-09-12T16:50:56+02:00 (7 years ago)
- Location:
- trunk/test/unit/org/openstreetmap/josm
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/actions/SplitWayActionTest.java
r12726 r12828 2 2 package org.openstreetmap.josm.actions; 3 3 4 import static org.junit.Assert.assertEquals;5 import static org.junit.Assert.assertNull;6 4 import static org.junit.Assert.assertSame; 7 5 import static org.junit.Assert.assertTrue; 8 6 9 import java.util.ArrayList;10 7 import java.util.Arrays; 11 import java.util.Iterator;12 8 13 9 import org.junit.Before; 14 10 import org.junit.Rule; 15 11 import org.junit.Test; 16 import org.openstreetmap.josm.actions.SplitWayAction.Strategy;17 12 import org.openstreetmap.josm.data.coor.EastNorth; 18 import org.openstreetmap.josm.data.coor.LatLon;19 13 import org.openstreetmap.josm.data.osm.DataSet; 20 14 import org.openstreetmap.josm.data.osm.Node; 21 import org.openstreetmap.josm.data.osm.OsmPrimitive;22 import org.openstreetmap.josm.data.osm.Relation;23 import org.openstreetmap.josm.data.osm.RelationMember;24 15 import org.openstreetmap.josm.data.osm.Way; 25 16 import org.openstreetmap.josm.gui.MainApplication; … … 112 103 } 113 104 } 114 115 /**116 * Unit test of {@link SplitWayAction#findVia}.117 */118 @Test119 public void testFindVia() {120 // empty relation121 assertNull(SplitWayAction.findVia(new Relation(), null));122 // restriction relation without via member123 Relation r = new Relation();124 r.addMember(new RelationMember("", new Node()));125 assertNull(SplitWayAction.findVia(r, "restriction"));126 // restriction relation with via member127 r = new Relation();128 OsmPrimitive via = new Node();129 r.addMember(new RelationMember("via", via));130 assertEquals(via, SplitWayAction.findVia(r, "restriction"));131 // destination_sign relation without sign nor intersection132 r = new Relation();133 r.addMember(new RelationMember("", new Node()));134 assertNull(SplitWayAction.findVia(r, "destination_sign"));135 // destination_sign with sign136 r = new Relation();137 via = new Node();138 r.addMember(new RelationMember("sign", via));139 assertEquals(via, SplitWayAction.findVia(r, "destination_sign"));140 // destination_sign with intersection141 r = new Relation();142 via = new Node();143 r.addMember(new RelationMember("intersection", via));144 assertEquals(via, SplitWayAction.findVia(r, "destination_sign"));145 }146 147 /**148 * Unit tests of route relations.149 */150 @Test151 public void testRouteRelation() {152 doTestRouteRelation(false, 0);153 doTestRouteRelation(false, 1);154 doTestRouteRelation(false, 2);155 doTestRouteRelation(false, 3);156 doTestRouteRelation(true, 0);157 doTestRouteRelation(true, 1);158 doTestRouteRelation(true, 2);159 doTestRouteRelation(true, 3);160 }161 162 void doTestRouteRelation(final boolean wayIsReversed, final int indexOfWayToKeep) {163 final DataSet dataSet = new DataSet();164 final Node n1 = new Node(new LatLon(1, 0));165 final Node n2 = new Node(new LatLon(2, 0));166 final Node n3 = new Node(new LatLon(3, 0));167 final Node n4 = new Node(new LatLon(4, 0));168 final Node n5 = new Node(new LatLon(5, 0));169 final Node n6 = new Node(new LatLon(6, 0));170 final Node n7 = new Node(new LatLon(7, 0));171 final Way w1 = new Way();172 final Way w2 = new Way();173 final Way w3 = new Way();174 final Relation route = new Relation();175 for (OsmPrimitive p : Arrays.asList(n1, n2, n3, n4, n5, n6, n7, w1, w2, w3, route)) {176 dataSet.addPrimitive(p);177 }178 w1.setNodes(Arrays.asList(n1, n2));179 w2.setNodes(wayIsReversed180 ? Arrays.asList(n6, n5, n4, n3, n2)181 : Arrays.asList(n2, n3, n4, n5, n6)182 );183 w3.setNodes(Arrays.asList(n6, n7));184 route.put("type", "route");185 route.addMember(new RelationMember("", w1));186 route.addMember(new RelationMember("", w2));187 route.addMember(new RelationMember("", w3));188 dataSet.setSelected(Arrays.asList(w2, n3, n4, n5));189 190 final Strategy strategy = wayChunks -> {191 final Iterator<Way> it = wayChunks.iterator();192 for (int i = 0; i < indexOfWayToKeep; i++) {193 it.next();194 }195 return it.next();196 };197 final SplitWayAction.SplitWayResult result = SplitWayAction.splitWay(198 w2, SplitWayAction.buildSplitChunks(w2, Arrays.asList(n3, n4, n5)), new ArrayList<OsmPrimitive>(), strategy);199 MainApplication.undoRedo.add(result.getCommand());200 201 assertEquals(6, route.getMembersCount());202 assertEquals(w1, route.getMemberPrimitivesList().get(0));203 assertEquals(w3, route.getMemberPrimitivesList().get(5));204 assertFirstLastNodeIs(((Way) route.getMemberPrimitivesList().get(0)), n1);205 assertFirstLastNodeIs(((Way) route.getMemberPrimitivesList().get(0)), n2);206 assertFirstLastNodeIs(((Way) route.getMemberPrimitivesList().get(1)), n2);207 assertFirstLastNodeIs(((Way) route.getMemberPrimitivesList().get(1)), n3);208 assertFirstLastNodeIs(((Way) route.getMemberPrimitivesList().get(2)), n3);209 assertFirstLastNodeIs(((Way) route.getMemberPrimitivesList().get(2)), n4);210 assertFirstLastNodeIs(((Way) route.getMemberPrimitivesList().get(3)), n4);211 assertFirstLastNodeIs(((Way) route.getMemberPrimitivesList().get(3)), n5);212 assertFirstLastNodeIs(((Way) route.getMemberPrimitivesList().get(4)), n5);213 assertFirstLastNodeIs(((Way) route.getMemberPrimitivesList().get(4)), n6);214 assertFirstLastNodeIs(((Way) route.getMemberPrimitivesList().get(5)), n6);215 assertFirstLastNodeIs(((Way) route.getMemberPrimitivesList().get(5)), n7);216 }217 218 static void assertFirstLastNodeIs(Way way, Node node) {219 assertTrue("First/last node of " + way + " should be " + node, node.equals(way.firstNode()) || node.equals(way.lastNode()));220 }221 105 }
Note:
See TracChangeset
for help on using the changeset viewer.