kopia lustrzana https://github.com/JOSM/MapWithAI
Add tests for merging duplicate ways, with some fixes
Signed-off-by: Taylor Smock <taylor.smock@kaart.com>pull/1/head
rodzic
e97e9e1dc6
commit
a470f9f95c
|
@ -36,22 +36,28 @@ public class MergeDuplicateWaysAction extends JosmAction {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
final List<Way> ways = new ArrayList<>(MainApplication.getLayerManager().getActiveDataSet().getSelectedWays());
|
if (MainApplication.getLayerManager().getActiveDataSet() != null) {
|
||||||
Command command = null;
|
final List<Way> ways = new ArrayList<>(MainApplication.getLayerManager().getActiveDataSet().getSelectedWays());
|
||||||
int i = 0;
|
Command command = null;
|
||||||
do {
|
int i = 0;
|
||||||
if (ways.size() == 2) {
|
do {
|
||||||
command = new MergeDuplicateWays(ways.get(0), ways.get(1));
|
if (ways.size() == 2) {
|
||||||
} else if (ways.size() == 1) {
|
command = new MergeDuplicateWays(ways.get(0), ways.get(1));
|
||||||
command = new MergeDuplicateWays(ways.get(0));
|
} else if (ways.size() == 1) {
|
||||||
} else if (ways.isEmpty()) {
|
command = new MergeDuplicateWays(ways.get(0));
|
||||||
command = new MergeDuplicateWays(MainApplication.getLayerManager().getActiveDataSet());
|
} else if (ways.isEmpty()) {
|
||||||
}
|
command = new MergeDuplicateWays(MainApplication.getLayerManager().getActiveDataSet());
|
||||||
if (command != null) {
|
}
|
||||||
UndoRedoHandler.getInstance().add(command);
|
if (command != null) {
|
||||||
i++;
|
UndoRedoHandler.getInstance().add(command);
|
||||||
}
|
i++;
|
||||||
} while (command != null && i < 1);
|
}
|
||||||
|
} while (command != null && i < 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateEnabledState() {
|
||||||
|
setEnabled(MainApplication.getLayerManager().getActiveDataSet() != null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,82 @@
|
||||||
|
// License: GPL. For details, see LICENSE file.
|
||||||
|
package org.openstreetmap.josm.plugins.mapwithai.backend;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Rule;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.openstreetmap.josm.TestUtils;
|
||||||
|
import org.openstreetmap.josm.data.UndoRedoHandler;
|
||||||
|
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.Way;
|
||||||
|
import org.openstreetmap.josm.gui.MainApplication;
|
||||||
|
import org.openstreetmap.josm.gui.layer.OsmDataLayer;
|
||||||
|
import org.openstreetmap.josm.testutils.JOSMTestRules;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Taylor Smock
|
||||||
|
*/
|
||||||
|
public class MergeDuplicateWaysActionTest {
|
||||||
|
@Rule
|
||||||
|
public JOSMTestRules rules = new JOSMTestRules().preferences().projection().main();
|
||||||
|
|
||||||
|
MergeDuplicateWaysAction action;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
action = new MergeDuplicateWaysAction();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testActionPerformed() {
|
||||||
|
action.actionPerformed(null);
|
||||||
|
MainApplication.getLayerManager().addLayer(new OsmDataLayer(new DataSet(), "Test Layer", null));
|
||||||
|
DataSet ds = MainApplication.getLayerManager().getActiveDataSet();
|
||||||
|
action.actionPerformed(null);
|
||||||
|
UndoRedoHandler.getInstance().undo();
|
||||||
|
|
||||||
|
Way way1 = TestUtils.newWay("", new Node(new LatLon(0, 0)), new Node(new LatLon(0, 1)));
|
||||||
|
Way way2 = TestUtils.newWay("", new Node(new LatLon(0, 0)), new Node(new LatLon(0, 1)));
|
||||||
|
Way way3 = TestUtils.newWay("", new Node(new LatLon(1, 1)), new Node(new LatLon(2, 1)));
|
||||||
|
for (Way way : Arrays.asList(way1, way2, way3)) {
|
||||||
|
way.getNodes().forEach(ds::addPrimitive);
|
||||||
|
ds.addPrimitive(way);
|
||||||
|
}
|
||||||
|
|
||||||
|
runCommand(way1, way2);
|
||||||
|
|
||||||
|
ds.setSelected(way1);
|
||||||
|
runCommand(way1, way2);
|
||||||
|
|
||||||
|
ds.addSelected(Collections.singleton(way2));
|
||||||
|
runCommand(way1, way2);
|
||||||
|
|
||||||
|
ds.addSelected(Collections.singleton(way3));
|
||||||
|
action.actionPerformed(null);
|
||||||
|
assertFalse(UndoRedoHandler.getInstance().hasUndoCommands());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void runCommand(Way way1, Way way2) {
|
||||||
|
action.actionPerformed(null);
|
||||||
|
assertNotEquals(way1.isDeleted(), way2.isDeleted());
|
||||||
|
UndoRedoHandler.getInstance().undo();
|
||||||
|
assertEquals(way1.isDeleted(), way2.isDeleted());
|
||||||
|
assertFalse(way1.isDeleted());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateEnabledState() {
|
||||||
|
assertFalse(action.isEnabled());
|
||||||
|
MainApplication.getLayerManager().addLayer(new OsmDataLayer(new DataSet(), "Test Layer", null));
|
||||||
|
assertTrue(action.isEnabled());
|
||||||
|
}
|
||||||
|
}
|
Ładowanie…
Reference in New Issue