Changeset 17408 in josm for trunk


Ignore:
Timestamp:
2020-12-14T11:52:24+01:00 (3 months ago)
Author:
GerdP
Message:

fix #20238: update multipolygon on old-style multipolygon action cannot be fully undone

  • make sure that a command to update the relation is generated
  • add unit test
Location:
trunk
Files:
2 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/CreateMultipolygonAction.java

    r17406 r17408  
    339339            return null;
    340340        }
    341         boolean unchanged = rr.a == rr.b;
     341        boolean changedMembers = rr.a != rr.b;
    342342        final Relation existingRelation = rr.a;
    343         final Relation relation = rr.b;
     343        final Relation relation = changedMembers ? rr.b : new Relation(rr.a);
    344344
    345345        final List<Command> list = removeTagsFromWaysIfNeeded(relation);
     
    349349            commandName = getName(false);
    350350        } else {
    351             if (!unchanged) {
    352                 if (relation.getKeys().equals(existingRelation.getKeys()))
    353                     list.add(new ChangeMembersCommand(existingRelation, new ArrayList<>(relation.getMembers())));
    354                 else
    355                     list.add(new ChangeCommand(existingRelation, relation));
     351            boolean changedKeys = !relation.getKeys().equals(existingRelation.getKeys());
     352            if (changedKeys && changedMembers)
     353                list.add(new ChangeCommand(existingRelation, relation));
     354            else if (changedMembers) {
     355                list.add(new ChangeMembersCommand(existingRelation, new ArrayList<>(relation.getMembers())));
     356            } else if (changedKeys) {
     357                list.add(ChangePropertyCommand.build(existingRelation, relation));
    356358            }
    357359            if (list.isEmpty()) {
    358                 if (unchanged) {
     360                if (!changedMembers) {
    359361                    MultipolygonTest mpTest = new MultipolygonTest();
    360362                    mpTest.visit(existingRelation);
  • trunk/test/unit/org/openstreetmap/josm/actions/CreateMultipolygonActionTest.java

    r17406 r17408  
    191191        assertEquals(0, ds.getWays().stream().filter(w -> w.hasTag("building", "yes")).count());
    192192    }
     193
     194    /**
     195     * Non-regression test for <a href="https://josm.openstreetmap.de/ticket/20238">Bug #20238</a>.
     196     * @throws Exception if an error occurs
     197     */
     198    @Test
     199    void testTicket20238() throws Exception {
     200        DataSet ds = OsmReader.parseDataSet(TestUtils.getRegressionDataStream(20238, "data.osm"), null);
     201        assertEquals(1, ds.getRelations().size());
     202        Relation mp = ds.getRelations().iterator().next();
     203        assertFalse(ds.getRelations().iterator().next().hasTag("building", "yes"));
     204        assertEquals(1, ds.getWays().stream().filter(w -> w.hasTag("building", "yes")).count());
     205        Pair<SequenceCommand, Relation> cmd = CreateMultipolygonAction.createMultipolygonCommand(ds.getWays(), mp);
     206        assertNotNull(cmd);
     207        cmd.a.executeCommand();
     208        assertEquals(1, ds.getRelations().size());
     209        assertTrue(ds.getRelations().iterator().next().hasTag("building", "yes"));
     210        assertEquals(0, ds.getWays().stream().filter(w -> w.hasTag("building", "yes")).count());
     211        cmd.a.undoCommand();
     212        assertEquals(1, ds.getRelations().size());
     213        assertFalse(ds.getRelations().iterator().next().hasTag("building", "yes"));
     214        assertEquals(1, ds.getWays().stream().filter(w -> w.hasTag("building", "yes")).count());
     215    }
    193216}
Note: See TracChangeset for help on using the changeset viewer.