Add test for #79. Currently only fails when run with other tests.

Signed-off-by: Taylor Smock <taylor.smock@kaart.com>
pull/1/head
Taylor Smock 2020-06-18 16:37:05 -06:00
rodzic 5cf2aafd1a
commit 8e46ca2a65
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 625F6A74A3E4311A
3 zmienionych plików z 44 dodań i 3 usunięć

Wyświetl plik

@ -24,6 +24,7 @@ import org.openstreetmap.josm.gui.MainApplication;
import org.openstreetmap.josm.gui.Notification;
import org.openstreetmap.josm.gui.layer.Layer;
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.commands.MapWithAIAddCommand;
import org.openstreetmap.josm.tools.Shortcut;
@ -75,7 +76,7 @@ public class MapWithAIMoveAction extends JosmAction {
&& (MapWithAIDataUtils.getAddedObjects() < maxAddition * MAX_ADD_MULTIPLIER))
|| (maxAddition == 0 && ExpertToggleAction.isExpert())) {
final MapWithAIAddCommand command = new MapWithAIAddCommand(mapWithAI, editLayer, selected);
UndoRedoHandler.getInstance().add(command);
GuiHelper.runInEDTAndWait(() -> UndoRedoHandler.getInstance().add(command));
if (MapWithAIPreferenceHelper.isSwitchLayers()) {
MainApplication.getLayerManager().setActiveLayer(editLayer);
}

Wyświetl plik

@ -140,7 +140,7 @@ public class MapWithAIDataUtilsTest {
@Test
public void testAddPaintStyle() {
MapWithAIDataUtils.removeMapWithAIPaintStyles();
Awaitility.await().atMost(Durations.FIVE_SECONDS)
Awaitility.await().atMost(Durations.TEN_SECONDS)
.until(() -> !MapWithAIDataUtils.checkIfMapWithAIPaintStyleExists());
List<StyleSource> paintStyles = MapPaintStyles.getStyles().getStyleSources();
for (int i = 0; i < 10; i++) {

Wyświetl plik

@ -1,12 +1,15 @@
// License: GPL. For details, see LICENSE file.
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.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.concurrent.Future;
import org.awaitility.Awaitility;
import org.awaitility.Durations;
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.testutils.JOSMTestRules;
import org.openstreetmap.josm.testutils.mockers.WindowMocker;
import org.openstreetmap.josm.tools.Territories;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import mockit.Mock;
@ -42,7 +46,7 @@ public class MapWithAIMoveActionTest {
@Rule
@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
public void setUp() {
@ -165,4 +169,40 @@ public class MapWithAIMoveActionTest {
assertTrue(notification.shown);
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());
}
}
}