Changeset 18610 in josm for trunk/test/unit/org


Ignore:
Timestamp:
2022-12-07T14:52:06+01:00 (2 years ago)
Author:
taylor.smock
Message:

Fix #21324: Command stack says "pasting 1 tag to [number] objects" regardless of how many tags are pasted

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/gui/datatransfer/OsmTransferHandlerTest.java

    r18464 r18610  
    22package org.openstreetmap.josm.gui.datatransfer;
    33
     4import static org.junit.jupiter.api.Assertions.assertAll;
    45import static org.junit.jupiter.api.Assertions.assertEquals;
    56import static org.junit.jupiter.api.Assertions.assertTrue;
    67
    78import java.util.Collections;
     9import java.util.stream.Stream;
    810
    911import org.junit.jupiter.api.extension.RegisterExtension;
    1012import org.junit.jupiter.api.Test;
     13import org.junit.jupiter.params.ParameterizedTest;
     14import org.junit.jupiter.params.provider.Arguments;
     15import org.junit.jupiter.params.provider.MethodSource;
    1116import org.openstreetmap.josm.actions.CopyAction;
     17import org.openstreetmap.josm.command.ChangePropertyCommand;
     18import org.openstreetmap.josm.command.Command;
     19import org.openstreetmap.josm.command.SequenceCommand;
     20import org.openstreetmap.josm.data.UndoRedoHandler;
    1221import org.openstreetmap.josm.data.coor.LatLon;
    1322import org.openstreetmap.josm.data.osm.DataSet;
     
    1524import org.openstreetmap.josm.data.projection.ProjectionRegistry;
    1625import org.openstreetmap.josm.gui.MainApplication;
     26import org.openstreetmap.josm.gui.datatransfer.data.PrimitiveTransferData;
    1727import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    1828import org.openstreetmap.josm.testutils.JOSMTestRules;
     
    7282        assertEquals("ok", n.get("test"));
    7383    }
     84
     85    static Stream<Arguments> testNonRegression21324() {
     86        return Stream.of(
     87                Arguments.of((Runnable) () -> ClipboardUtils.copyString("test=ok\rsomething=else\nnew=line")),
     88                Arguments.of((Runnable) () -> {
     89                    Node nData = new Node();
     90                    nData.put("test", "ok");
     91                    nData.put("something", "else");
     92                    nData.put("new", "line");
     93                    ClipboardUtils.copy(new PrimitiveTransferable(
     94                            PrimitiveTransferData.getDataWithReferences(Collections.singletonList(nData)), null));
     95                })
     96        );
     97    }
     98
     99    /**
     100     * Non-regression test for #21324: Command stack says "pasting 1 tag to [number] objects" regardless of how many tags are pasted
     101     */
     102    @ParameterizedTest
     103    @MethodSource
     104    void testNonRegression21324(Runnable clipboardCopy) {
     105        clipboardCopy.run();
     106        Node n = new Node(LatLon.ZERO);
     107        MainApplication.getLayerManager().addLayer(new OsmDataLayer(new DataSet(n), "testNonRegression21324", null));
     108
     109        transferHandler.pasteTags(Collections.singleton(n));
     110        Command command = UndoRedoHandler.getInstance().getLastCommand();
     111
     112        assertAll(() -> assertEquals("ok", n.get("test")),
     113                () -> assertEquals("else", n.get("something")),
     114                () -> assertEquals("line", n.get("new")),
     115                () -> assertEquals(1, UndoRedoHandler.getInstance().getUndoCommands().size()),
     116                () -> assertTrue((command instanceof SequenceCommand
     117                        && command.getChildren().stream().allMatch(ChangePropertyCommand.class::isInstance))
     118                || command instanceof ChangePropertyCommand),
     119                () -> assertEquals("Sequence: Pasting 3 tags to 1 object", command.getDescriptionText()));
     120    }
    74121}
Note: See TracChangeset for help on using the changeset viewer.