Ticket #20110: 20110.patch

File 20110.patch, 4.8 KB (added by GerdP, 4 years ago)

patch and unit test

  • src/org/openstreetmap/josm/actions/CreateMultipolygonAction.java

     
    416416                for (String key : way.keySet()) {
    417417                    if (!values.containsKey(key)) { //relation values take precedence
    418418                        values.put(key, way.get(key));
    419                     } else if (!relation.hasKey(key) && !values.get(key).equals(way.get(key))) {
     419                    } else if (!values.get(key).equals(way.get(key))) {
    420420                        conflictingKeys.add(key);
    421421                    }
    422422                }
  • test/data/regress/20110/data.osm

     
     1<?xml version='1.0' encoding='UTF-8'?>
     2<osm version='0.6' upload='never' generator='JOSM'>
     3  <node id='-101770' action='modify' visible='true' lat='52.8825296301' lon='8.42060908349' />
     4  <node id='-101771' action='modify' visible='true' lat='52.88854640489' lon='8.44962466717' />
     5  <node id='-101772' action='modify' visible='true' lat='52.89813899419' lon='8.46022478752' />
     6  <node id='-101773' action='modify' visible='true' lat='52.90491214264' lon='8.45681118944' />
     7  <node id='-101774' action='modify' visible='true' lat='52.88388483241' lon='8.41512936025' />
     8  <node id='-101775' action='modify' visible='true' lat='52.88290329214' lon='8.41611375352' />
     9  <node id='-101777' action='modify' visible='true' lat='52.88990212311' lon='8.4328166643' />
     10  <node id='-101778' action='modify' visible='true' lat='52.89224037406' lon='8.43774185623' />
     11  <node id='-101779' action='modify' visible='true' lat='52.88839193568' lon='8.43854926475' />
     12  <way id='-101791' action='modify' visible='true'>
     13    <nd ref='-101770' />
     14    <nd ref='-101771' />
     15    <nd ref='-101772' />
     16    <nd ref='-101773' />
     17    <tag k='natural' v='coastline' />
     18  </way>
     19  <way id='-101795' action='modify' visible='true'>
     20    <nd ref='-101774' />
     21    <nd ref='-101775' />
     22    <nd ref='-101770' />
     23  </way>
     24  <way id='-101799' action='modify' visible='true'>
     25    <nd ref='-101773' />
     26    <nd ref='-101774' />
     27    <tag k='natural' v='coastline' />
     28  </way>
     29  <way id='-101805' action='modify' visible='true'>
     30    <nd ref='-101777' />
     31    <nd ref='-101778' />
     32    <nd ref='-101779' />
     33    <nd ref='-101777' />
     34  </way>
     35  <relation id='-99748' action='modify' visible='true'>
     36    <member type='way' ref='-101795' role='outer' />
     37    <member type='way' ref='-101799' role='outer' />
     38    <member type='way' ref='-101791' role='outer' />
     39    <tag k='natural' v='wetland' />
     40    <tag k='type' v='multipolygon' />
     41  </relation>
     42</osm>
  • test/unit/org/openstreetmap/josm/actions/CreateMultipolygonActionTest.java

     
    33
    44import static org.junit.jupiter.api.Assertions.assertEquals;
    55import static org.junit.jupiter.api.Assertions.assertFalse;
     6import static org.junit.jupiter.api.Assertions.assertNotNull;
    67import static org.junit.jupiter.api.Assertions.assertTrue;
    78
    89import java.nio.file.Files;
     
    1112import java.util.Map;
    1213import java.util.TreeMap;
    1314
     15import org.junit.jupiter.api.Test;
    1416import org.junit.jupiter.api.extension.RegisterExtension;
    15 import org.junit.jupiter.api.Test;
    1617import org.openstreetmap.josm.TestUtils;
    1718import org.openstreetmap.josm.command.SequenceCommand;
    1819import org.openstreetmap.josm.data.osm.DataSet;
     
    155156        }
    156157
    157158    }
     159
     160    /**
     161     * Non-regression test for <a href="https://josm.openstreetmap.de/ticket/20110">Bug #20110</a>.
     162     * @throws Exception if an error occurs
     163     */
     164    @Test
     165    void testTicket20110() throws Exception {
     166        DataSet ds = OsmReader.parseDataSet(TestUtils.getRegressionDataStream(20110, "data.osm"), null);
     167        assertEquals(1, ds.getRelations().size());
     168        Relation mp = ds.getRelations().iterator().next();
     169        assertEquals("wetland", mp.get("natural"));
     170        long numCoastlineWays = ds.getWays().stream().filter(w -> "coastline".equals(w.get("natural"))).count();
     171        Relation modMp = createMultipolygon(ds.getWays(), "type:way", mp, false);
     172        assertNotNull(modMp);
     173        assertEquals("wetland", modMp.get("natural"));
     174        assertEquals(numCoastlineWays, ds.getWays().stream().filter(w -> "coastline".equals(w.get("natural"))).count());
     175    }
    158176}