kopia lustrzana https://github.com/JOSM/MapWithAI
Add test for #79. Currently only fails when run with other tests.
Signed-off-by: Taylor Smock <taylor.smock@kaart.com>pull/1/head
rodzic
5cf2aafd1a
commit
8e46ca2a65
|
@ -24,6 +24,7 @@ import org.openstreetmap.josm.gui.MainApplication;
|
||||||
import org.openstreetmap.josm.gui.Notification;
|
import org.openstreetmap.josm.gui.Notification;
|
||||||
import org.openstreetmap.josm.gui.layer.Layer;
|
import org.openstreetmap.josm.gui.layer.Layer;
|
||||||
import org.openstreetmap.josm.gui.layer.OsmDataLayer;
|
import org.openstreetmap.josm.gui.layer.OsmDataLayer;
|
||||||
|
import org.openstreetmap.josm.gui.util.GuiHelper;
|
||||||
import org.openstreetmap.josm.plugins.mapwithai.MapWithAIPlugin;
|
import org.openstreetmap.josm.plugins.mapwithai.MapWithAIPlugin;
|
||||||
import org.openstreetmap.josm.plugins.mapwithai.commands.MapWithAIAddCommand;
|
import org.openstreetmap.josm.plugins.mapwithai.commands.MapWithAIAddCommand;
|
||||||
import org.openstreetmap.josm.tools.Shortcut;
|
import org.openstreetmap.josm.tools.Shortcut;
|
||||||
|
@ -75,7 +76,7 @@ public class MapWithAIMoveAction extends JosmAction {
|
||||||
&& (MapWithAIDataUtils.getAddedObjects() < maxAddition * MAX_ADD_MULTIPLIER))
|
&& (MapWithAIDataUtils.getAddedObjects() < maxAddition * MAX_ADD_MULTIPLIER))
|
||||||
|| (maxAddition == 0 && ExpertToggleAction.isExpert())) {
|
|| (maxAddition == 0 && ExpertToggleAction.isExpert())) {
|
||||||
final MapWithAIAddCommand command = new MapWithAIAddCommand(mapWithAI, editLayer, selected);
|
final MapWithAIAddCommand command = new MapWithAIAddCommand(mapWithAI, editLayer, selected);
|
||||||
UndoRedoHandler.getInstance().add(command);
|
GuiHelper.runInEDTAndWait(() -> UndoRedoHandler.getInstance().add(command));
|
||||||
if (MapWithAIPreferenceHelper.isSwitchLayers()) {
|
if (MapWithAIPreferenceHelper.isSwitchLayers()) {
|
||||||
MainApplication.getLayerManager().setActiveLayer(editLayer);
|
MainApplication.getLayerManager().setActiveLayer(editLayer);
|
||||||
}
|
}
|
||||||
|
|
|
@ -140,7 +140,7 @@ public class MapWithAIDataUtilsTest {
|
||||||
@Test
|
@Test
|
||||||
public void testAddPaintStyle() {
|
public void testAddPaintStyle() {
|
||||||
MapWithAIDataUtils.removeMapWithAIPaintStyles();
|
MapWithAIDataUtils.removeMapWithAIPaintStyles();
|
||||||
Awaitility.await().atMost(Durations.FIVE_SECONDS)
|
Awaitility.await().atMost(Durations.TEN_SECONDS)
|
||||||
.until(() -> !MapWithAIDataUtils.checkIfMapWithAIPaintStyleExists());
|
.until(() -> !MapWithAIDataUtils.checkIfMapWithAIPaintStyleExists());
|
||||||
List<StyleSource> paintStyles = MapPaintStyles.getStyles().getStyleSources();
|
List<StyleSource> paintStyles = MapPaintStyles.getStyles().getStyleSources();
|
||||||
for (int i = 0; i < 10; i++) {
|
for (int i = 0; i < 10; i++) {
|
||||||
|
|
|
@ -1,12 +1,15 @@
|
||||||
// License: GPL. For details, see LICENSE file.
|
// License: GPL. For details, see LICENSE file.
|
||||||
package org.openstreetmap.josm.plugins.mapwithai.backend;
|
package org.openstreetmap.josm.plugins.mapwithai.backend;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
import java.util.concurrent.Future;
|
||||||
|
|
||||||
import org.awaitility.Awaitility;
|
import org.awaitility.Awaitility;
|
||||||
import org.awaitility.Durations;
|
import org.awaitility.Durations;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
@ -28,6 +31,7 @@ import org.openstreetmap.josm.plugins.mapwithai.backend.commands.conflation.Dupl
|
||||||
import org.openstreetmap.josm.plugins.mapwithai.testutils.MissingConnectionTagsMocker;
|
import org.openstreetmap.josm.plugins.mapwithai.testutils.MissingConnectionTagsMocker;
|
||||||
import org.openstreetmap.josm.testutils.JOSMTestRules;
|
import org.openstreetmap.josm.testutils.JOSMTestRules;
|
||||||
import org.openstreetmap.josm.testutils.mockers.WindowMocker;
|
import org.openstreetmap.josm.testutils.mockers.WindowMocker;
|
||||||
|
import org.openstreetmap.josm.tools.Territories;
|
||||||
|
|
||||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||||
import mockit.Mock;
|
import mockit.Mock;
|
||||||
|
@ -42,7 +46,7 @@ public class MapWithAIMoveActionTest {
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
@SuppressFBWarnings("URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
@SuppressFBWarnings("URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
||||||
public JOSMTestRules test = new JOSMTestRules().preferences().main().projection();
|
public JOSMTestRules test = new JOSMTestRules().preferences().main().projection().territories();
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
|
@ -165,4 +169,40 @@ public class MapWithAIMoveActionTest {
|
||||||
assertTrue(notification.shown);
|
assertTrue(notification.shown);
|
||||||
notification.shown = false;
|
notification.shown = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is a non-regression test. There used to be an AssertionError when an
|
||||||
|
* address and building were added, and then was undone. See
|
||||||
|
* <a href="https://gitlab.com/gokaart/JOSM_MapWithAI/-/issues/79">Issue #79</a>
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testBuildingAndAddressAdd() {
|
||||||
|
// Required to avoid an NPE in Territories.getRegionalTaginfoUrls
|
||||||
|
Future<?> territoriesRegionalTaginfo = MainApplication.worker.submit(() -> Territories.initialize());
|
||||||
|
DataSet ds = MapWithAIDataUtils.getLayer(true).getDataSet();
|
||||||
|
Way building = TestUtils.newWay("building=yes", new Node(new LatLon(38.236811, -104.62571)),
|
||||||
|
new Node(new LatLon(38.236811, -104.625493)), new Node(new LatLon(38.236716, -104.625493)),
|
||||||
|
new Node(new LatLon(38.236716, -104.62571)));
|
||||||
|
building.getNodes().forEach(ds::addPrimitive);
|
||||||
|
ds.addPrimitive(building);
|
||||||
|
building.addNode(building.firstNode());
|
||||||
|
Node address = TestUtils.newNode(
|
||||||
|
"addr:city=Pueblo addr:housenumber=1901 addr:postcode=81004 addr:street=\"Lake Avenue\" mapwithai:source=\"Statewide Aggregate Addresses in Colorado 2019 (Public)\"");
|
||||||
|
address.setCoor(new LatLon(38.2367599, -104.6255641));
|
||||||
|
ds.addPrimitive(address);
|
||||||
|
|
||||||
|
DataSet ds2 = new DataSet();
|
||||||
|
MainApplication.getLayerManager().addLayer(new OsmDataLayer(ds2, "TEST LAYER", null));
|
||||||
|
|
||||||
|
// The building/address need to be selected separately
|
||||||
|
// This is due to only allowing 1 additional selection at a time.
|
||||||
|
ds.setSelected(building);
|
||||||
|
ds.addSelected(address);
|
||||||
|
// Wait for territories to finish
|
||||||
|
assertDoesNotThrow(() -> territoriesRegionalTaginfo.get());
|
||||||
|
GuiHelper.runInEDTAndWaitWithException(() -> moveAction.actionPerformed(null));
|
||||||
|
while (UndoRedoHandler.getInstance().hasUndoCommands()) {
|
||||||
|
assertDoesNotThrow(() -> UndoRedoHandler.getInstance().undo());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Ładowanie…
Reference in New Issue