Check for random cases to ensure that they don't break

Signed-off-by: Taylor Smock <taylor.smock@kaart.com>
pull/1/head
Taylor Smock 2019-10-02 11:39:11 -06:00
rodzic 9e0ef154c4
commit b87214b7ef
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 625F6A74A3E4311A
3 zmienionych plików z 61 dodań i 9 usunięć

Wyświetl plik

@ -96,6 +96,9 @@ public class DeletePrimitivesCommand extends Command {
@Override
public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted,
Collection<OsmPrimitive> added) {
for (Command command : commands) {
command.fillModifiedData(modified, deleted, added);
}
deleted.addAll(removed);
}

Wyświetl plik

@ -26,7 +26,6 @@ public class MovePrimitiveDataSetCommand extends Command {
private final DataSet from;
private final Collection<OsmPrimitive> primitives;
private SequenceCommand command;
List<Command> commands;
public MovePrimitiveDataSetCommand(DataSet to, DataSet from, Collection<OsmPrimitive> primitives) {
super(to);
@ -34,15 +33,14 @@ public class MovePrimitiveDataSetCommand extends Command {
this.from = from;
this.primitives = primitives;
command = null;
commands = new ArrayList<>();
}
@Override
public boolean executeCommand() {
if (to.equals(from))
return false;
command = moveCollection(from, to, primitives);
if (command != null) {
command.executeCommand();
}
return true;
}
/**
@ -53,11 +51,13 @@ public class MovePrimitiveDataSetCommand extends Command {
* @param selection The primitives to move
*/
public SequenceCommand moveCollection(DataSet from, DataSet to, Collection<OsmPrimitive> selection) {
if (from == null || to.isLocked() || from.isLocked()) {
if (from == null || to.isLocked() || from.isLocked() || to.equals(from)) {
Logging.error("{0}: Cannot move primitives from {1} to {2}", RapiDPlugin.NAME, from, to);
return null;
}
List<Command> commands = new ArrayList<>();
Collection<OsmPrimitive> allNeededPrimitives = new ArrayList<>();
RapiDDataUtils.addPrimitivesToCollection(allNeededPrimitives, selection);
@ -71,8 +71,10 @@ public class MovePrimitiveDataSetCommand extends Command {
@Override
public void undoCommand() {
if (command != null) {
command.undoCommand();
}
}
@Override
public String getDescriptionText() {
@ -82,6 +84,6 @@ public class MovePrimitiveDataSetCommand extends Command {
@Override
public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted,
Collection<OsmPrimitive> added) {
modified.addAll(primitives);
command.fillModifiedData(modified, deleted, added);
}
}

Wyświetl plik

@ -1,6 +1,9 @@
// License: GPL. For details, see LICENSE file.
package org.openstreetmap.josm.plugins.rapid.commands;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import org.junit.Assert;
@ -10,8 +13,8 @@ import org.openstreetmap.josm.TestUtils;
import org.openstreetmap.josm.data.coor.LatLon;
import org.openstreetmap.josm.data.osm.DataSet;
import org.openstreetmap.josm.data.osm.Node;
import org.openstreetmap.josm.data.osm.OsmPrimitive;
import org.openstreetmap.josm.data.osm.Way;
import org.openstreetmap.josm.plugins.rapid.commands.MovePrimitiveDataSetCommand;
import org.openstreetmap.josm.testutils.JOSMTestRules;
public class MovePrimitiveDataSetCommandTest {
@ -20,6 +23,9 @@ public class MovePrimitiveDataSetCommandTest {
@Test
public void testMovePrimitives() {
Collection<OsmPrimitive> added = new ArrayList<>();
Collection<OsmPrimitive> modified = new ArrayList<>();
Collection<OsmPrimitive> deleted = new ArrayList<>();
DataSet to = new DataSet();
DataSet from = new DataSet();
Way way1 = TestUtils.newWay("highway=tertiary", new Node(new LatLon(0, 0)), new Node(new LatLon(0.1, 0.1)));
@ -32,6 +38,10 @@ public class MovePrimitiveDataSetCommandTest {
Assert.assertEquals(4, from.allPrimitives().size());
move.executeCommand();
move.fillModifiedData(modified, deleted, added);
Assert.assertEquals(3, deleted.size());
Assert.assertEquals(3, added.size());
Assert.assertEquals(0, modified.size());
Assert.assertEquals(1, from.allPrimitives().size());
Assert.assertEquals(3, to.allPrimitives().size());
Assert.assertEquals(to, way1.getDataSet());
@ -43,7 +53,14 @@ public class MovePrimitiveDataSetCommandTest {
way1.firstNode().put("highway", "stop");
modified.clear();
added.clear();
deleted.clear();
move.executeCommand();
move.fillModifiedData(modified, deleted, added);
Assert.assertEquals(3, deleted.size());
Assert.assertEquals(3, added.size());
Assert.assertEquals(0, modified.size());
Assert.assertEquals(1, from.allPrimitives().size());
Assert.assertEquals(3, to.allPrimitives().size());
Assert.assertEquals(to, way1.getDataSet());
@ -52,5 +69,35 @@ public class MovePrimitiveDataSetCommandTest {
Assert.assertEquals(0, to.allPrimitives().size());
Assert.assertEquals(4, from.allPrimitives().size());
Assert.assertEquals(from, way1.getDataSet());
for (DataSet ds : Arrays.asList(from, to)) {
ds.lock();
move.executeCommand();
Assert.assertEquals(0, to.allPrimitives().size());
Assert.assertEquals(4, from.allPrimitives().size());
Assert.assertEquals(from, way1.getDataSet());
move.undoCommand();
ds.unlock();
}
move = new MovePrimitiveDataSetCommand(to, null, Collections.singleton(way1));
move.executeCommand();
Assert.assertEquals(0, to.allPrimitives().size());
Assert.assertEquals(4, from.allPrimitives().size());
Assert.assertEquals(from, way1.getDataSet());
move.undoCommand();
move = new MovePrimitiveDataSetCommand(to, to, Collections.singleton(way1));
move.executeCommand();
Assert.assertEquals(0, to.allPrimitives().size());
Assert.assertEquals(4, from.allPrimitives().size());
Assert.assertEquals(from, way1.getDataSet());
move.undoCommand();
}
@Test
public void testDescription() {
Assert.assertNotNull(new MovePrimitiveDataSetCommand(new DataSet(), new DataSet(), Collections.emptyList())
.getDescriptionText());
}
}