Changeset 19228 in josm
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/DataSetMerger.java
r19175 r19228 141 141 protected void addConflict(OsmPrimitive my, OsmPrimitive their) { 142 142 addConflict(new Conflict<>(my, their)); 143 } 144 145 private void replaceConflict(Conflict<?> oldConflict, Conflict<?> newConflict) { 146 newConflict.setMergedMap(mergedMap); 147 conflicts.remove(oldConflict); 148 conflicts.add(newConflict); 143 149 } 144 150 … … 326 332 // otherwise too many conflicts when refreshing from the server 327 333 // but, if source is modified, there is a conflict 334 Conflict<?> currentConflict = null; 328 335 if (source.isModified()) { 329 addConflict(new Conflict<>(target, source, true)); 336 currentConflict = new Conflict<>(target, source, true); 337 addConflict(currentConflict); 330 338 } 331 339 // or, if source has a referrer that is not in the target dataset there is a conflict … … 333 341 for (OsmPrimitive referrer: source.getReferrers()) { 334 342 if (targetDataSet.getPrimitiveById(referrer.getPrimitiveId()) == null) { 335 addConflict(new Conflict<>(target, source, true)); 343 final Conflict<?> newConflict = new Conflict<>(target, source, true); 344 if (currentConflict != null) { // See #23930 345 replaceConflict(currentConflict, newConflict); 346 } else { 347 addConflict(newConflict); 348 } 336 349 target.setDeleted(false); 337 350 break; -
trunk/test/unit/org/openstreetmap/josm/data/osm/DataSetMergerTest.java
r19175 r19228 2 2 package org.openstreetmap.josm.data.osm; 3 3 4 import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; 4 5 import static org.junit.jupiter.api.Assertions.assertEquals; 5 6 import static org.junit.jupiter.api.Assertions.assertFalse; 7 import static org.junit.jupiter.api.Assertions.assertInstanceOf; 6 8 import static org.junit.jupiter.api.Assertions.assertNotNull; 7 9 import static org.junit.jupiter.api.Assertions.assertNotSame; … … 11 13 import static org.junit.jupiter.api.Assertions.fail; 12 14 15 import java.io.File; 16 import java.io.IOException; 13 17 import java.io.StringWriter; 14 18 import java.time.Instant; 15 19 import java.util.Arrays; 20 import java.util.List; 16 21 import java.util.function.BiConsumer; 22 import java.util.stream.Collectors; 17 23 import java.util.stream.Stream; 18 24 … … 22 28 import org.junit.jupiter.params.ParameterizedTest; 23 29 import org.junit.jupiter.params.provider.MethodSource; 30 import org.openstreetmap.josm.TestUtils; 31 import org.openstreetmap.josm.data.conflict.Conflict; 32 import org.openstreetmap.josm.data.conflict.ConflictCollection; 24 33 import org.openstreetmap.josm.data.coor.LatLon; 25 34 import org.openstreetmap.josm.data.projection.ProjectionRegistry; 26 35 import org.openstreetmap.josm.data.projection.Projections; 36 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 27 37 import org.openstreetmap.josm.gui.progress.NullProgressMonitor; 38 import org.openstreetmap.josm.io.IllegalDataException; 39 import org.openstreetmap.josm.io.session.SessionReader; 40 import org.openstreetmap.josm.tools.Logging; 28 41 29 42 /** … … 1361 1374 } 1362 1375 1363 static Stream<BiConsumer<Node, Node>> test NonRegression23846() {1376 static Stream<BiConsumer<Node, Node>> testTicket23846() { 1364 1377 return Stream.of( 1365 1378 (firstNode, secondNode) -> firstNode.setModified(true), … … 1370 1383 @ParameterizedTest 1371 1384 @MethodSource 1372 void test NonRegression23846(BiConsumer<Node, Node> nodeSetup) {1385 void testTicket23846(BiConsumer<Node, Node> nodeSetup) { 1373 1386 final Node firstNode = new Node(1234, 1); 1374 1387 final Node secondNode = new Node(1234, 1); … … 1386 1399 assertTrue(secondNode.isReferrersDownloaded()); 1387 1400 } 1401 1402 /** 1403 * Non-regression test for <a href="https://josm.openstreetmap.de/ticket/23930">#23930</a> 1404 */ 1405 @Test 1406 void testTicket23930() throws IOException, IllegalDataException { 1407 final File file = new File(TestUtils.getRegressionDataFile(23930, "JOSM_conflict.joz")); 1408 final SessionReader reader = new SessionReader(); 1409 reader.loadSession(file, true, NullProgressMonitor.INSTANCE); 1410 final List<OsmDataLayer> layers = reader.getLayers().stream() 1411 .filter(OsmDataLayer.class::isInstance).map(OsmDataLayer.class::cast).collect(Collectors.toList()); 1412 final DataSet newWay = layers.stream().filter(layer -> layer.getName().equals("new_way.osm")) 1413 .map(OsmDataLayer::getDataSet).findFirst().orElseThrow(); 1414 final DataSet nodeDeleted = layers.stream().filter(layer -> layer.getName().equals("node_deleted.osm")) 1415 .map(OsmDataLayer::getDataSet).findFirst().orElseThrow(); 1416 final DataSetMerger merge = new DataSetMerger(nodeDeleted, newWay); 1417 Logging.clearLastErrorAndWarnings(); 1418 assertDoesNotThrow(() -> merge.merge(NullProgressMonitor.INSTANCE)); 1419 assertTrue(Logging.getLastErrorAndWarnings().isEmpty(), String.join("\n", Logging.getLastErrorAndWarnings())); 1420 final ConflictCollection conflicts = merge.getConflicts(); 1421 // There are a few differences in the files 1422 // 1. New node in layer 2: No need for conflict 1423 // 2. node 2427358529: layer 1 deletes it, layer 2 modifies it (conflict required) 1424 // 3. new way in layer 2 with new node and node 2427358529 (conflict required) 1425 // 4. Modification of way 32277602 in layer 1 removing node 2427358529 (conflict required) 1426 // Therefore, conflicts are as follows: 1427 // 1. A deleted node (n2427358529) with referrers (w32277602 and new way) and new tags ("fix tag=recheck position") 1428 assertEquals(1, conflicts.size()); 1429 final Conflict<?> conflict = conflicts.iterator().next(); 1430 final Node myNode = assertInstanceOf(Node.class, conflict.getMy()); 1431 final Node theirNode = assertInstanceOf(Node.class, conflict.getTheir()); 1432 assertFalse(theirNode.isDeleted()); 1433 assertFalse(myNode.isDeleted()); 1434 } 1388 1435 }
Note:
See TracChangeset
for help on using the changeset viewer.