Move to Assertions from Assert and add comments to asserts

Signed-off-by: Taylor Smock <taylor.smock@kaart.com>
pull/1/head
Taylor Smock 2019-12-16 11:19:34 -07:00
rodzic b5fd3ffb23
commit e58f941fbb
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 625F6A74A3E4311A
12 zmienionych plików z 312 dodań i 276 usunięć

Wyświetl plik

@ -2,12 +2,12 @@
package org.openstreetmap.josm.plugins.mapwithai; package org.openstreetmap.josm.plugins.mapwithai;
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.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotNull;
import javax.swing.SpinnerNumberModel; import javax.swing.SpinnerNumberModel;
import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
@ -87,6 +87,6 @@ public class MapWithAIPreferencesTest {
*/ */
@Test @Test
public void testIsExpert() { public void testIsExpert() {
Assert.assertFalse(preferences.isExpert()); assertFalse(preferences.isExpert(), "This is not an expert only preference panel");
} }
} }

Wyświetl plik

@ -1,7 +1,12 @@
// 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 org.junit.Assert; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.openstreetmap.josm.data.coor.LatLon; import org.openstreetmap.josm.data.coor.LatLon;
@ -10,7 +15,6 @@ import org.openstreetmap.josm.data.gpx.WayPoint;
import org.openstreetmap.josm.data.osm.BBox; import org.openstreetmap.josm.data.osm.BBox;
import org.openstreetmap.josm.gui.MainApplication; import org.openstreetmap.josm.gui.MainApplication;
import org.openstreetmap.josm.gui.layer.GpxLayer; import org.openstreetmap.josm.gui.layer.GpxLayer;
import org.openstreetmap.josm.plugins.mapwithai.backend.DetectTaskingManagerUtils;
import org.openstreetmap.josm.testutils.JOSMTestRules; import org.openstreetmap.josm.testutils.JOSMTestRules;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
@ -28,48 +32,50 @@ public class DetectTaskingManagerUtilsTest {
@Test @Test
public void testHasTaskingManagerLayer() { public void testHasTaskingManagerLayer() {
Assert.assertFalse(DetectTaskingManagerUtils.hasTaskingManagerLayer()); assertFalse(DetectTaskingManagerUtils.hasTaskingManagerLayer(), "No TM layer exists yet");
MainApplication.getLayerManager().addLayer(new GpxLayer(new GpxData())); MainApplication.getLayerManager().addLayer(new GpxLayer(new GpxData()));
Assert.assertFalse(DetectTaskingManagerUtils.hasTaskingManagerLayer()); assertFalse(DetectTaskingManagerUtils.hasTaskingManagerLayer(), "No TM layer exists yet");
MainApplication.getLayerManager().addLayer(new GpxLayer(new GpxData(), LAYER_NAME)); MainApplication.getLayerManager().addLayer(new GpxLayer(new GpxData(), LAYER_NAME));
Assert.assertTrue(DetectTaskingManagerUtils.hasTaskingManagerLayer()); assertTrue(DetectTaskingManagerUtils.hasTaskingManagerLayer(), "A TM layer exists yet");
} }
@Test @Test
public void testGetTaskingManagerLayer() { public void testGetTaskingManagerLayer() {
Assert.assertNull(DetectTaskingManagerUtils.getTaskingManagerLayer()); assertNull(DetectTaskingManagerUtils.getTaskingManagerLayer(), "No TM layer exists yet");
final GpxLayer layer = new GpxLayer(new GpxData(), LAYER_NAME); final GpxLayer layer = new GpxLayer(new GpxData(), LAYER_NAME);
MainApplication.getLayerManager().addLayer(layer); MainApplication.getLayerManager().addLayer(layer);
Assert.assertSame(layer, DetectTaskingManagerUtils.getTaskingManagerLayer()); assertSame(layer, DetectTaskingManagerUtils.getTaskingManagerLayer(), "The TM layer was added");
} }
@Test @Test
public void testGetTaskingManagerBounds() { public void testGetTaskingManagerBounds() {
Assert.assertFalse(DetectTaskingManagerUtils.getTaskingManagerBBox().isInWorld()); assertFalse(DetectTaskingManagerUtils.getTaskingManagerBBox().isInWorld(), "No TM layer exists yet");
final GpxLayer layer = new GpxLayer(new GpxData(), LAYER_NAME); final GpxLayer layer = new GpxLayer(new GpxData(), LAYER_NAME);
layer.data.addWaypoint(new WayPoint(new LatLon(0, 0))); layer.data.addWaypoint(new WayPoint(new LatLon(0, 0)));
MainApplication.getLayerManager().addLayer(layer); MainApplication.getLayerManager().addLayer(layer);
Assert.assertEquals(0, DetectTaskingManagerUtils.getTaskingManagerBBox().height(), 0.000001); assertEquals(0, DetectTaskingManagerUtils.getTaskingManagerBBox().height(), 0.000001,
Assert.assertEquals(0, DetectTaskingManagerUtils.getTaskingManagerBBox().width(), 0.000001); "The TM layer only has one point");
assertEquals(0, DetectTaskingManagerUtils.getTaskingManagerBBox().width(), 0.000001,
"The TM layer only has one point");
layer.data.addWaypoint(new WayPoint(new LatLon(1, 1))); layer.data.addWaypoint(new WayPoint(new LatLon(1, 1)));
final BBox bbox = DetectTaskingManagerUtils.getTaskingManagerBBox(); final BBox bbox = DetectTaskingManagerUtils.getTaskingManagerBBox();
Assert.assertTrue(bbox.isInWorld()); assertTrue(bbox.isInWorld(), "A TM layer exists");
Assert.assertTrue(bbox.getBottomRight().equalsEpsilon(new LatLon(0, 1))); assertTrue(bbox.getBottomRight().equalsEpsilon(new LatLon(0, 1)), "The bottom right should be at (0, 1)");
Assert.assertTrue(bbox.getTopLeft().equalsEpsilon(new LatLon(1, 0))); assertTrue(bbox.getTopLeft().equalsEpsilon(new LatLon(1, 0)), "The top left should be at (1, 0)");
} }
@Test @Test
public void testCreateTaskingManagerGpxBounds() { public void testCreateTaskingManagerGpxBounds() {
Assert.assertFalse(DetectTaskingManagerUtils.hasTaskingManagerLayer()); assertFalse(DetectTaskingManagerUtils.hasTaskingManagerLayer(), "No TM layer exists yet");
final BBox bbox = new BBox(0, 0, 1, 1); final BBox bbox = new BBox(0, 0, 1, 1);
MainApplication.getLayerManager() MainApplication.getLayerManager()
.addLayer(new GpxLayer(DetectTaskingManagerUtils.createTaskingManagerGpxData(bbox), .addLayer(new GpxLayer(DetectTaskingManagerUtils.createTaskingManagerGpxData(bbox),
DetectTaskingManagerUtils.MAPWITHAI_CROP_AREA)); DetectTaskingManagerUtils.MAPWITHAI_CROP_AREA));
Assert.assertTrue(DetectTaskingManagerUtils.hasTaskingManagerLayer()); assertTrue(DetectTaskingManagerUtils.hasTaskingManagerLayer(), "A TM layer exists");
Assert.assertTrue(DetectTaskingManagerUtils.getTaskingManagerBBox().bounds(bbox)); assertTrue(DetectTaskingManagerUtils.getTaskingManagerBBox().bounds(bbox), "The TM layer should bound itself");
} }
} }

Wyświetl plik

@ -2,12 +2,12 @@
package org.openstreetmap.josm.plugins.mapwithai.backend; package org.openstreetmap.josm.plugins.mapwithai.backend;
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options; import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeTrue; import static org.junit.Assume.assumeTrue;
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.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;

Wyświetl plik

@ -3,10 +3,11 @@ package org.openstreetmap.josm.plugins.mapwithai.backend;
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options; import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
import static org.awaitility.Awaitility.await; import static org.awaitility.Awaitility.await;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.awaitility.Durations; import org.awaitility.Durations;
import org.junit.After; import org.junit.After;
import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
@ -46,30 +47,32 @@ public class MapWithAIAvailabilityTest {
@Test @Test
public void testHasDataBBox() { public void testHasDataBBox() {
Assert.assertFalse(instance.hasData(new BBox(0, 0, 0.1, 0.1))); assertFalse(instance.hasData(new BBox(0, 0, 0.1, 0.1)), "There shouldn't be data in the ocean");
Assert.assertTrue(instance.hasData(new BBox(-99.9, 39.9, 100.1, 40.1))); assertTrue(instance.hasData(new BBox(-99.9, 39.9, 100.1, 40.1)), "There should be data in the US");
} }
@Test @Test
public void testHasDataLatLon() { public void testHasDataLatLon() {
Assert.assertFalse(instance.hasData(new LatLon(0, 0))); assertFalse(instance.hasData(new LatLon(0, 0)), "There should not be data in the ocean");
Assert.assertTrue(instance.hasData(new LatLon(40, -100))); assertTrue(instance.hasData(new LatLon(40, -100)), "There should be data in the US");
Assert.assertTrue(instance.hasData(new LatLon(45.424722, -75.695))); assertTrue(instance.hasData(new LatLon(45.424722, -75.695)), "There should be data in Canada");
Assert.assertTrue(instance.hasData(new LatLon(19.433333, -99.133333))); assertTrue(instance.hasData(new LatLon(19.433333, -99.133333)), "There should be data in Mexico");
} }
@Test @Test
public void testgetDataLatLon() { public void testgetDataLatLon() {
Assert.assertTrue(DataAvailability.getDataTypes(new LatLon(0, 0)).isEmpty()); assertTrue(DataAvailability.getDataTypes(new LatLon(0, 0)).isEmpty(), "There should not be data in the ocean");
Assert.assertTrue(DataAvailability.getDataTypes(new LatLon(40, -100)).getOrDefault("highway", false)); assertTrue(DataAvailability.getDataTypes(new LatLon(40, -100)).getOrDefault("highway", false),
Assert.assertTrue(DataAvailability.getDataTypes(new LatLon(40, -100)).getOrDefault("building", false)); "The US should have highway data");
Assert.assertFalse( assertTrue(DataAvailability.getDataTypes(new LatLon(40, -100)).getOrDefault("building", false),
DataAvailability.getDataTypes(new LatLon(45.424722, -75.695)).getOrDefault("highway", false)); "The US should have building data");
Assert.assertTrue( assertFalse(DataAvailability.getDataTypes(new LatLon(45.424722, -75.695)).getOrDefault("highway", false),
DataAvailability.getDataTypes(new LatLon(45.424722, -75.695)).getOrDefault("building", false)); "Canada does not yet have highway data");
Assert.assertTrue( assertTrue(DataAvailability.getDataTypes(new LatLon(45.424722, -75.695)).getOrDefault("building", false),
DataAvailability.getDataTypes(new LatLon(19.433333, -99.133333)).getOrDefault("highway", false)); "Canada does have building data");
Assert.assertFalse( assertTrue(DataAvailability.getDataTypes(new LatLon(19.433333, -99.133333)).getOrDefault("highway", false),
DataAvailability.getDataTypes(new LatLon(19.433333, -99.133333)).getOrDefault("building", false)); "Mexico has highway data");
assertFalse(DataAvailability.getDataTypes(new LatLon(19.433333, -99.133333)).getOrDefault("building", false),
"Mexico does not yet have building data");
} }
} }

Wyświetl plik

@ -2,8 +2,12 @@
package org.openstreetmap.josm.plugins.mapwithai.backend; package org.openstreetmap.josm.plugins.mapwithai.backend;
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options; import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@ -14,7 +18,6 @@ import java.util.stream.Collectors;
import org.awaitility.Awaitility; import org.awaitility.Awaitility;
import org.awaitility.Durations; import org.awaitility.Durations;
import org.junit.After; import org.junit.After;
import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
@ -78,7 +81,7 @@ public class MapWithAIDataUtilsTest {
public void testGetData() { public void testGetData() {
final BBox testBBox = getTestBBox(); final BBox testBBox = getTestBBox();
final DataSet ds = new DataSet(MapWithAIDataUtils.getData(testBBox)); final DataSet ds = new DataSet(MapWithAIDataUtils.getData(testBBox));
Assert.assertEquals(1, ds.getWays().size()); assertEquals(1, ds.getWays().size(), "There should only be one way in the testBBox");
} }
/** /**
@ -95,10 +98,10 @@ public class MapWithAIDataUtilsTest {
final DataSet originalData = MapWithAIDataUtils.getData(testBBox); final DataSet originalData = MapWithAIDataUtils.getData(testBBox);
MainApplication.getLayerManager().addLayer(gpx); MainApplication.getLayerManager().addLayer(gpx);
final DataSet ds = MapWithAIDataUtils.getData(testBBox); final DataSet ds = MapWithAIDataUtils.getData(testBBox);
Assert.assertEquals(1, ds.getWays().size()); assertEquals(1, ds.getWays().size(), "There should only be one way in the cropped testBBox");
Assert.assertEquals(3, ds.getNodes().size()); assertEquals(3, ds.getNodes().size(), "There should be three nodes in the cropped testBBox");
Assert.assertEquals(1, originalData.getWays().size()); assertEquals(1, originalData.getWays().size(), "There should be one way in the testBBox");
Assert.assertEquals(4, originalData.getNodes().size()); assertEquals(4, originalData.getNodes().size(), "There should be four nodes in the testBBox");
} }
@Test @Test
@ -108,9 +111,9 @@ public class MapWithAIDataUtilsTest {
final DataSet ds = new DataSet(way1.firstNode(), way1.lastNode(), way1); final DataSet ds = new DataSet(way1.firstNode(), way1.lastNode(), way1);
final String source = "random source"; final String source = "random source";
Assert.assertNull(way1.get("source")); assertNull(way1.get("source"), "The source for the data should not be null");
MapWithAIDataUtils.addSourceTags(ds, "highway", source); MapWithAIDataUtils.addSourceTags(ds, "highway", source);
Assert.assertEquals(source, way1.get("source")); assertEquals(source, way1.get("source"), "The source for the data should be the specified source");
} }
public static BBox getTestBBox() { public static BBox getTestBBox() {
@ -125,9 +128,8 @@ public class MapWithAIDataUtilsTest {
final Way way1 = TestUtils.newWay("highway=residential", new Node(new LatLon(0, 0)), final Way way1 = TestUtils.newWay("highway=residential", new Node(new LatLon(0, 0)),
new Node(new LatLon(0, 0.1))); new Node(new LatLon(0, 0.1)));
final Collection<OsmPrimitive> collection = new TreeSet<>(); final Collection<OsmPrimitive> collection = new TreeSet<>();
Assert.assertEquals(0, collection.size());
MapWithAIDataUtils.addPrimitivesToCollection(collection, Collections.singletonList(way1)); MapWithAIDataUtils.addPrimitivesToCollection(collection, Collections.singletonList(way1));
Assert.assertEquals(3, collection.size()); assertEquals(3, collection.size(), "The way has two child primitives, for a total of three primitives");
} }
@Test @Test
@ -140,9 +142,9 @@ public class MapWithAIDataUtilsTest {
} }
ds1.addPrimitive(way1); ds1.addPrimitive(way1);
Assert.assertEquals(3, ds1.allPrimitives().size()); assertEquals(3, ds1.allPrimitives().size(), "The DataSet should have three primitives");
MapWithAIDataUtils.removePrimitivesFromDataSet(Collections.singleton(way1)); MapWithAIDataUtils.removePrimitivesFromDataSet(Collections.singleton(way1));
Assert.assertEquals(0, ds1.allPrimitives().size()); assertEquals(0, ds1.allPrimitives().size(), "All of the primitives should have been removed from the DataSet");
} }
@Test @Test
@ -152,65 +154,54 @@ public class MapWithAIDataUtilsTest {
.until(() -> !MapWithAIDataUtils.checkIfMapWithAIPaintStyleExists()); .until(() -> !MapWithAIDataUtils.checkIfMapWithAIPaintStyleExists());
List<StyleSource> paintStyles = MapPaintStyles.getStyles().getStyleSources(); List<StyleSource> paintStyles = MapPaintStyles.getStyles().getStyleSources();
int initialSize = paintStyles.size(); int initialSize = paintStyles.size();
Assert.assertEquals(initialSize, paintStyles.size()); for (int i = 0; i < 10; i++) {
MapWithAIDataUtils.addMapWithAIPaintStyles(); MapWithAIDataUtils.addMapWithAIPaintStyles();
paintStyles = MapPaintStyles.getStyles().getStyleSources(); paintStyles = MapPaintStyles.getStyles().getStyleSources();
Assert.assertEquals(initialSize + 1, paintStyles.size()); assertEquals(initialSize + 1, paintStyles.size(),
MapWithAIDataUtils.addMapWithAIPaintStyles(); "The paintstyle should have been added, but only one of it");
paintStyles = MapPaintStyles.getStyles().getStyleSources(); }
Assert.assertEquals(initialSize + 1, paintStyles.size());
MapWithAIDataUtils.addMapWithAIPaintStyles();
} }
@Test @Test
public void testMapWithAIURLPreferences() { public void testMapWithAIURLPreferences() {
final String fakeUrl = "https://fake.url"; final String fakeUrl = "https://fake.url";
Assert.assertTrue(MapWithAIPreferenceHelper.getMapWithAIUrl().parallelStream() assertTrue(MapWithAIPreferenceHelper.getMapWithAIUrl().parallelStream().noneMatch(
.noneMatch(map -> fakeUrl.equals(map.get("url")))); map -> fakeUrl.equals(map.get("url"))), "fakeUrl shouldn't be in the current MapWithAI urls");
MapWithAIPreferenceHelper.setMapWithAIUrl("Fake", fakeUrl, true, true); MapWithAIPreferenceHelper.setMapWithAIUrl("Fake", fakeUrl, true, true);
Assert.assertTrue(MapWithAIPreferenceHelper.getMapWithAIUrl().parallelStream() assertTrue(MapWithAIPreferenceHelper.getMapWithAIUrl().parallelStream()
.anyMatch(map -> fakeUrl.equals(map.get("url")))); .anyMatch(map -> fakeUrl.equals(map.get("url"))), "fakeUrl should have been added");
final List<Map<String, String>> urls = new ArrayList<>(MapWithAIPreferenceHelper.getMapWithAIURLs()); final List<Map<String, String>> urls = new ArrayList<>(MapWithAIPreferenceHelper.getMapWithAIURLs());
Assert.assertEquals(2, urls.size()); assertEquals(2, urls.size(), "There should be two urls (fakeUrl and the default)");
MapWithAIPreferenceHelper.setMapWithAIUrl("MapWithAI", MapWithAIPreferenceHelper.DEFAULT_MAPWITHAI_API, true, MapWithAIPreferenceHelper.setMapWithAIUrl("MapWithAI", MapWithAIPreferenceHelper.DEFAULT_MAPWITHAI_API, true,
true); true);
Assert.assertTrue(MapWithAIPreferenceHelper.getMapWithAIUrl().parallelStream() assertTrue(
.anyMatch(map -> MapWithAIPreferenceHelper.DEFAULT_MAPWITHAI_API.equals(map.get("url")))); MapWithAIPreferenceHelper.getMapWithAIUrl().parallelStream()
.anyMatch(map -> MapWithAIPreferenceHelper.DEFAULT_MAPWITHAI_API.equals(map.get("url"))),
"The default URL should exist");
MapWithAIPreferenceHelper.setMapWithAIUrl("Fake2", fakeUrl, true, true); MapWithAIPreferenceHelper.setMapWithAIUrl("Fake2", fakeUrl, true, true);
Assert.assertEquals(1, MapWithAIPreferenceHelper.getMapWithAIUrl().parallelStream() assertEquals(1, MapWithAIPreferenceHelper.getMapWithAIUrl().parallelStream()
.filter(map -> fakeUrl.equals(map.get("url"))).count()); .filter(map -> fakeUrl.equals(map.get("url"))).count(), "There should only be one fakeUrl");
MapWithAIPreferenceHelper.setMapWithAIURLs(urls.parallelStream() MapWithAIPreferenceHelper.setMapWithAIURLs(urls.parallelStream()
.filter(map -> !fakeUrl.equalsIgnoreCase(map.getOrDefault("url", ""))).collect(Collectors.toList())); .filter(map -> !fakeUrl.equalsIgnoreCase(map.getOrDefault("url", ""))).collect(Collectors.toList()));
Assert.assertEquals(1, MapWithAIPreferenceHelper.getMapWithAIUrl().size()); assertEquals(1, MapWithAIPreferenceHelper.getMapWithAIUrl().size(),
Assert.assertTrue(MapWithAIPreferenceHelper.getMapWithAIUrl().parallelStream() "The MapWithAI URLs should have been reset (essentially)");
assertTrue(MapWithAIPreferenceHelper.getMapWithAIUrl().parallelStream()
.anyMatch(map -> getDefaultMapWithAIAPIForTest(MapWithAIPreferenceHelper.DEFAULT_MAPWITHAI_API) .anyMatch(map -> getDefaultMapWithAIAPIForTest(MapWithAIPreferenceHelper.DEFAULT_MAPWITHAI_API)
.equals(map.get("url")))); .equals(map.get("url"))),
"The MapWithAI URLs should have been reset");
} }
@Test @Test
public void testSplitBounds() { public void testSplitBounds() {
final BBox bbox = new BBox(0, 0, 0.0001, 0.0001); final BBox bbox = new BBox(0, 0, 0.0001, 0.0001);
for (Double i : Arrays.asList(0.0001, 0.001, 0.01, 0.1)) {
bbox.add(i, i);
List<BBox> bboxes = MapWithAIDataUtils.reduceBBoxSize(bbox); List<BBox> bboxes = MapWithAIDataUtils.reduceBBoxSize(bbox);
Assert.assertEquals(getExpectedNumberOfBBoxes(bbox), bboxes.size()); assertEquals(getExpectedNumberOfBBoxes(bbox), bboxes.size(), "The bbox should be appropriately reduced");
checkInBBox(bbox, bboxes);
bbox.add(0.001, 0.001);
bboxes = MapWithAIDataUtils.reduceBBoxSize(bbox);
Assert.assertEquals(getExpectedNumberOfBBoxes(bbox), bboxes.size());
checkInBBox(bbox, bboxes);
bbox.add(0.01, 0.01);
bboxes = MapWithAIDataUtils.reduceBBoxSize(bbox);
Assert.assertEquals(getExpectedNumberOfBBoxes(bbox), bboxes.size());
checkInBBox(bbox, bboxes);
checkBBoxesConnect(bbox, bboxes);
bbox.add(0.1, 0.1);
bboxes = MapWithAIDataUtils.reduceBBoxSize(bbox);
Assert.assertEquals(getExpectedNumberOfBBoxes(bbox), bboxes.size());
checkInBBox(bbox, bboxes); checkInBBox(bbox, bboxes);
checkBBoxesConnect(bbox, bboxes); checkBBoxesConnect(bbox, bboxes);
} }
}
private static int getExpectedNumberOfBBoxes(BBox bbox) { private static int getExpectedNumberOfBBoxes(BBox bbox) {
double width = MapWithAIDataUtils.getWidth(bbox); double width = MapWithAIDataUtils.getWidth(bbox);
@ -222,7 +213,7 @@ public class MapWithAIDataUtilsTest {
private static void checkInBBox(BBox bbox, Collection<BBox> bboxes) { private static void checkInBBox(BBox bbox, Collection<BBox> bboxes) {
for (final BBox tBBox : bboxes) { for (final BBox tBBox : bboxes) {
Assert.assertTrue(bbox.bounds(tBBox)); assertTrue(bbox.bounds(tBBox), "The bboxes should all be inside the original bbox");
} }
} }
@ -240,7 +231,7 @@ public class MapWithAIDataUtilsTest {
if (!bboxFoundConnections) { if (!bboxFoundConnections) {
bboxFoundConnections = bboxCheckConnections(bbox1, originalBBox); bboxFoundConnections = bboxCheckConnections(bbox1, originalBBox);
} }
Assert.assertTrue(bboxFoundConnections); assertTrue(bboxFoundConnections, "The bbox should connect to other bboxes");
} }
} }

Wyświetl plik

@ -3,6 +3,12 @@ package org.openstreetmap.josm.plugins.mapwithai.backend;
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options; import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
import static org.awaitility.Awaitility.await; import static org.awaitility.Awaitility.await;
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.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.openstreetmap.josm.tools.I18n.tr; import static org.openstreetmap.josm.tools.I18n.tr;
import java.awt.Component; import java.awt.Component;
@ -16,7 +22,6 @@ import javax.swing.JPanel;
import org.awaitility.Durations; import org.awaitility.Durations;
import org.junit.After; import org.junit.After;
import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
@ -70,7 +75,7 @@ public class MapWithAILayerTest {
@Test @Test
public void testGetSource() { public void testGetSource() {
Assert.assertNull(layer.getChangesetSourceTag()); assertNull(layer.getChangesetSourceTag(), "The source tag should be null");
DataSet to = new DataSet(); DataSet to = new DataSet();
DataSet from = new DataSet(); DataSet from = new DataSet();
Way way = TestUtils.newWay("", new Node(new LatLon(0, 0)), new Node(new LatLon(1, 1))); Way way = TestUtils.newWay("", new Node(new LatLon(0, 0)), new Node(new LatLon(1, 1)));
@ -79,23 +84,25 @@ public class MapWithAILayerTest {
way.put(GetDataRunnable.MAPWITHAI_SOURCE_TAG_KEY, MapWithAIPlugin.NAME); way.put(GetDataRunnable.MAPWITHAI_SOURCE_TAG_KEY, MapWithAIPlugin.NAME);
MapWithAIAddCommand command = new MapWithAIAddCommand(from, to, Collections.singleton(way)); MapWithAIAddCommand command = new MapWithAIAddCommand(from, to, Collections.singleton(way));
UndoRedoHandler.getInstance().add(command); UndoRedoHandler.getInstance().add(command);
Assert.assertNotNull(layer.getChangesetSourceTag()); assertNotNull(layer.getChangesetSourceTag(), "The source tag should not be null");
Assert.assertFalse(layer.getChangesetSourceTag().trim().isEmpty()); assertFalse(layer.getChangesetSourceTag().trim().isEmpty(), "The source tag should not be an empty string");
Assert.assertEquals(MapWithAIPlugin.NAME, layer.getChangesetSourceTag()); assertEquals(MapWithAIPlugin.NAME, layer.getChangesetSourceTag(),
"The source tag should be the plugin name (by default)");
} }
@Test @Test
public void testGetInfoComponent() { public void testGetInfoComponent() {
final Object tObject = layer.getInfoComponent(); final Object tObject = layer.getInfoComponent();
Assert.assertTrue(tObject instanceof JPanel); assertTrue(tObject instanceof JPanel, "The info component should be a JPanel instead of a string");
JPanel jPanel = (JPanel) tObject; JPanel jPanel = (JPanel) tObject;
final List<Component> startComponents = Arrays.asList(jPanel.getComponents()); final List<Component> startComponents = Arrays.asList(jPanel.getComponents());
for (final Component comp : startComponents) { for (final Component comp : startComponents) {
final JLabel label = (JLabel) comp; final JLabel label = (JLabel) comp;
Assert.assertFalse(label.getText().contains("URL")); assertFalse(label.getText().contains("URL"), "The layer doesn't have a custom URL");
Assert.assertFalse(label.getText().contains("Maximum Additions")); assertFalse(label.getText().contains("Maximum Additions"), "The layer doesn't have its own max additions");
Assert.assertFalse(label.getText().contains("Switch Layers")); assertFalse(label.getText().contains("Switch Layers"),
"The layer doesn't have its own switchlayer boolean");
} }
layer.setMapWithAIUrl("bad_url"); layer.setMapWithAIUrl("bad_url");
@ -108,11 +115,13 @@ public class MapWithAILayerTest {
for (final Component comp : currentComponents) { for (final Component comp : currentComponents) {
final JLabel label = (JLabel) comp; final JLabel label = (JLabel) comp;
if (label.getText().contains("URL")) { if (label.getText().contains("URL")) {
Assert.assertEquals(tr("URL: {0}", "bad_url"), label.getText()); assertEquals(tr("URL: {0}", "bad_url"), label.getText(), "The layer should have the bad_url set");
} else if (label.getText().contains("Maximum Additions")) { } else if (label.getText().contains("Maximum Additions")) {
Assert.assertEquals(tr("Maximum Additions: {0}", 0), label.getText()); assertEquals(tr("Maximum Additions: {0}", 0), label.getText(),
"The layer should have max additions set");
} else if (label.getText().contains("Switch Layers")) { } else if (label.getText().contains("Switch Layers")) {
Assert.assertEquals(tr("Switch Layers: {0}", false), label.getText()); assertEquals(tr("Switch Layers: {0}", false), label.getText(),
"The layer should have switchlayers set");
} }
} }
} }
@ -120,16 +129,16 @@ public class MapWithAILayerTest {
@Test @Test
public void testGetLayer() { public void testGetLayer() {
Layer mapWithAILayer = MapWithAIDataUtils.getLayer(false); Layer mapWithAILayer = MapWithAIDataUtils.getLayer(false);
Assert.assertNull(mapWithAILayer); assertNull(mapWithAILayer, "There should be no MapWithAI layer yet");
mapWithAILayer = MapWithAIDataUtils.getLayer(true); mapWithAILayer = MapWithAIDataUtils.getLayer(true);
Assert.assertEquals(MapWithAILayer.class, mapWithAILayer.getClass()); assertEquals(MapWithAILayer.class, mapWithAILayer.getClass(),
"The MapWithAI layer should be of the MapWithAILayer.class");
Layer tMapWithAI = MapWithAIDataUtils.getLayer(false); for (Boolean create : Arrays.asList(Boolean.FALSE, Boolean.TRUE)) {
Assert.assertSame(mapWithAILayer, tMapWithAI); Layer tMapWithAI = MapWithAIDataUtils.getLayer(create);
assertSame(mapWithAILayer, tMapWithAI, "getLayer should always return the same layer");
tMapWithAI = MapWithAIDataUtils.getLayer(true); }
Assert.assertSame(mapWithAILayer, tMapWithAI);
} }
@Test @Test
@ -139,27 +148,31 @@ public class MapWithAILayerTest {
MainApplication.getLayerManager().addLayer(osm); MainApplication.getLayerManager().addLayer(osm);
MapWithAIDataUtils.getMapWithAIData(mapWithAILayer, osm); MapWithAIDataUtils.getMapWithAIData(mapWithAILayer, osm);
Assert.assertTrue(mapWithAILayer.getDataSet().getDataSourceBounds().isEmpty()); assertTrue(mapWithAILayer.getDataSet().getDataSourceBounds().isEmpty(), "There should be no data source yet");
osm.getDataSet().addDataSource(new DataSource(new Bounds(0, 0, 0.001, 0.001), "random test")); osm.getDataSet().addDataSource(new DataSource(new Bounds(0, 0, 0.001, 0.001), "random test"));
osm.lock(); osm.lock();
MapWithAIDataUtils.getMapWithAIData(mapWithAILayer); MapWithAIDataUtils.getMapWithAIData(mapWithAILayer);
Assert.assertTrue(mapWithAILayer.getDataSet().getDataSourceBounds().isEmpty()); assertTrue(mapWithAILayer.getDataSet().getDataSourceBounds().isEmpty(),
"There should be no data due to the lock");
osm.unlock(); osm.unlock();
MapWithAIDataUtils.getMapWithAIData(mapWithAILayer); MapWithAIDataUtils.getMapWithAIData(mapWithAILayer);
await().atMost(Durations.TEN_SECONDS).until(() -> !mapWithAILayer.getDataSet().getDataSourceBounds().isEmpty()); await().atMost(Durations.TEN_SECONDS).until(() -> !mapWithAILayer.getDataSet().getDataSourceBounds().isEmpty());
Assert.assertFalse(mapWithAILayer.getDataSet().getDataSourceBounds().isEmpty()); assertFalse(mapWithAILayer.getDataSet().getDataSourceBounds().isEmpty(), "There should be a data source");
Assert.assertEquals(1, mapWithAILayer.getDataSet().getDataSourceBounds().parallelStream().distinct().count()); assertEquals(1, mapWithAILayer.getDataSet().getDataSourceBounds().parallelStream().distinct().count(),
"There should only be one data source");
osm.getDataSet().addDataSource(new DataSource(new Bounds(-0.001, -0.001, 0, 0), "random test")); osm.getDataSet().addDataSource(new DataSource(new Bounds(-0.001, -0.001, 0, 0), "random test"));
MapWithAIDataUtils.getMapWithAIData(mapWithAILayer); MapWithAIDataUtils.getMapWithAIData(mapWithAILayer);
await().atMost(Durations.TEN_SECONDS).until( await().atMost(Durations.TEN_SECONDS).until(
() -> mapWithAILayer.getDataSet().getDataSourceBounds().parallelStream().distinct().count() == 2); () -> mapWithAILayer.getDataSet().getDataSourceBounds().parallelStream().distinct().count() == 2);
Assert.assertEquals(2, mapWithAILayer.getDataSet().getDataSourceBounds().parallelStream().distinct().count()); assertEquals(2, mapWithAILayer.getDataSet().getDataSourceBounds().parallelStream().distinct().count(),
"There should be two data sources");
MapWithAIDataUtils.getMapWithAIData(mapWithAILayer); MapWithAIDataUtils.getMapWithAIData(mapWithAILayer);
Assert.assertEquals(2, mapWithAILayer.getDataSet().getDataSourceBounds().parallelStream().distinct().count()); assertEquals(2, mapWithAILayer.getDataSet().getDataSourceBounds().parallelStream().distinct().count(),
"There should be two data sources");
} }
} }

Wyświetl plik

@ -1,7 +1,12 @@
// 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 org.junit.Assert; 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 org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
@ -54,10 +59,11 @@ public class MapWithAIMoveActionTest {
public void testMoveAction() { public void testMoveAction() {
mapWithAIData.addSelected(way1); mapWithAIData.addSelected(way1);
moveAction.actionPerformed(null); moveAction.actionPerformed(null);
Assert.assertEquals(osmLayer, MainApplication.getLayerManager().getActiveLayer()); assertEquals(osmLayer, MainApplication.getLayerManager().getActiveLayer(),
Assert.assertNotNull(osmLayer.getDataSet().getPrimitiveById(way1)); "Current layer should be the OMS layer");
assertNotNull(osmLayer.getDataSet().getPrimitiveById(way1), "way1 should have been added to the OSM layer");
UndoRedoHandler.getInstance().undo(); UndoRedoHandler.getInstance().undo();
Assert.assertNull(osmLayer.getDataSet().getPrimitiveById(way1)); assertNull(osmLayer.getDataSet().getPrimitiveById(way1), "way1 should have been removed from the OSM layer");
} }
@Test @Test
@ -69,14 +75,16 @@ public class MapWithAIMoveActionTest {
final DataSet ds = osmLayer.getDataSet(); final DataSet ds = osmLayer.getDataSet();
moveAction.actionPerformed(null); moveAction.actionPerformed(null);
Assert.assertTrue( assertTrue(((Way) ds.getPrimitiveById(way1)).lastNode().equals(((Way) ds.getPrimitiveById(way2)).lastNode()),
((Way) ds.getPrimitiveById(way1)).lastNode().equals(((Way) ds.getPrimitiveById(way2)).lastNode())); "The duplicate node should have been replaced");
Assert.assertFalse(((Way) ds.getPrimitiveById(way2)).lastNode().hasKey(DuplicateCommand.DUPE_KEY)); assertFalse(((Way) ds.getPrimitiveById(way2)).lastNode().hasKey(DuplicateCommand.DUPE_KEY),
Assert.assertFalse(((Way) ds.getPrimitiveById(way1)).lastNode().hasKey(DuplicateCommand.DUPE_KEY)); "The dupe key should no longer exist");
assertFalse(((Way) ds.getPrimitiveById(way1)).lastNode().hasKey(DuplicateCommand.DUPE_KEY),
"The dupe key should no longer exist");
UndoRedoHandler.getInstance().undo(); UndoRedoHandler.getInstance().undo();
Assert.assertFalse(way2.lastNode().hasKey(DuplicateCommand.DUPE_KEY)); assertFalse(way2.lastNode().hasKey(DuplicateCommand.DUPE_KEY), "The dupe key should no longer exist");
Assert.assertTrue(way1.lastNode().hasKey(DuplicateCommand.DUPE_KEY)); assertTrue(way1.lastNode().hasKey(DuplicateCommand.DUPE_KEY), "The dupe key should no longer exist");
} }
@Test @Test
@ -88,14 +96,14 @@ public class MapWithAIMoveActionTest {
mapWithAIData.addSelected(way1); mapWithAIData.addSelected(way1);
moveAction.actionPerformed(null); moveAction.actionPerformed(null);
Assert.assertFalse(way2.lastNode().hasKey(ConnectedCommand.CONN_KEY)); assertFalse(way2.lastNode().hasKey(ConnectedCommand.CONN_KEY), "The conn key should have been removed");
Assert.assertFalse(way2.firstNode().hasKey(ConnectedCommand.CONN_KEY)); assertFalse(way2.firstNode().hasKey(ConnectedCommand.CONN_KEY), "The conn key should have been removed");
Assert.assertFalse(way2.getNode(1).hasKey(ConnectedCommand.CONN_KEY)); assertFalse(way2.getNode(1).hasKey(ConnectedCommand.CONN_KEY), "The conn key should have been removed");
Assert.assertTrue(way1.lastNode().isDeleted()); assertTrue(way1.lastNode().isDeleted(), "way1 should be deleted when added");
UndoRedoHandler.getInstance().undo(); UndoRedoHandler.getInstance().undo();
Assert.assertFalse(way2.lastNode().hasKey(ConnectedCommand.CONN_KEY)); assertFalse(way2.lastNode().hasKey(ConnectedCommand.CONN_KEY), "The conn key shouldn't exist");
Assert.assertTrue(way1.lastNode().hasKey(ConnectedCommand.CONN_KEY)); assertTrue(way1.lastNode().hasKey(ConnectedCommand.CONN_KEY), "The conn key should exist");
Assert.assertFalse(way1.lastNode().isDeleted()); assertFalse(way1.lastNode().isDeleted(), "way1 should no longer be deleted");
} }
} }

Wyświetl plik

@ -3,6 +3,9 @@
*/ */
package org.openstreetmap.josm.plugins.mapwithai.backend; package org.openstreetmap.josm.plugins.mapwithai.backend;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.InputStream; import java.io.InputStream;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
@ -11,7 +14,6 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.TreeMap; import java.util.TreeMap;
import org.junit.Assert;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.openstreetmap.josm.TestUtils; import org.openstreetmap.josm.TestUtils;
@ -64,19 +66,20 @@ public class MapWithAIUploadHookTest {
aiLayer.getDataSet().addPrimitive(way2); aiLayer.getDataSet().addPrimitive(way2);
Map<String, String> tags = new TreeMap<>(); Map<String, String> tags = new TreeMap<>();
Assert.assertTrue(tags.isEmpty());
hook.modifyChangesetTags(tags); hook.modifyChangesetTags(tags);
Assert.assertTrue(tags.isEmpty()); assertTrue(tags.isEmpty(), "Tags should be empty due to no primitives being added");
aiLayer.getDataSet().setSelected(way1); aiLayer.getDataSet().setSelected(way1);
MapWithAIMoveAction action = new MapWithAIMoveAction(); MapWithAIMoveAction action = new MapWithAIMoveAction();
action.actionPerformed(null); action.actionPerformed(null);
hook.modifyChangesetTags(tags); hook.modifyChangesetTags(tags);
Assert.assertEquals(2, tags.size()); assertEquals(2, tags.size(), "Tags should not be empty due to adding primitives");
Assert.assertEquals(Integer.toString(1), tags.get("mapwithai")); assertEquals(Integer.toString(1), tags.get("mapwithai"),
Assert.assertTrue( "mapwithai should equal 1, due to adding one primitive");
Arrays.asList(tags.get("mapwithai:options").split(";")).contains("version=".concat(info.localversion))); assertTrue(
Arrays.asList(tags.get("mapwithai:options").split(";")).contains("version=".concat(info.localversion)),
"The version should be the localversion");
MapWithAIPreferenceHelper.setMapWithAIUrl("False URL", "false-url", true, true); MapWithAIPreferenceHelper.setMapWithAIUrl("False URL", "false-url", true, true);
@ -86,21 +89,21 @@ public class MapWithAIUploadHookTest {
action.actionPerformed(null); action.actionPerformed(null);
hook.modifyChangesetTags(tags); hook.modifyChangesetTags(tags);
Assert.assertEquals(Integer.toString(2), tags.get("mapwithai")); assertEquals(Integer.toString(2), tags.get("mapwithai"), "Two objects have been added");
Assert.assertEquals(2, tags.size()); assertEquals(2, tags.size(), "Tags should not be empty due to adding primitives");
List<String> split = Arrays.asList(tags.get("mapwithai:options").split(";")); List<String> split = Arrays.asList(tags.get("mapwithai:options").split(";"));
Assert.assertEquals(2, split.size()); assertEquals(2, split.size(), "There should be another option in mapwithai:options");
Assert.assertTrue(split.contains("version=".concat(info.localversion))); assertTrue(split.contains("version=".concat(info.localversion)), "The version should match the local version");
Assert.assertTrue(split.contains("url=false-url")); assertTrue(split.contains("url=false-url"), "The false-url should be shown in the changeset tag");
MapWithAIPreferenceHelper.setMaximumAddition(20, false); MapWithAIPreferenceHelper.setMaximumAddition(20, false);
tags.clear(); tags.clear();
hook.modifyChangesetTags(tags); hook.modifyChangesetTags(tags);
split = Arrays.asList(tags.get("mapwithai:options").split(";")); split = Arrays.asList(tags.get("mapwithai:options").split(";"));
Assert.assertEquals(3, split.size()); assertEquals(3, split.size(), "There should be three ; in mapwithai:options");
Assert.assertTrue(split.contains("version=".concat(info.localversion))); assertTrue(split.contains("version=".concat(info.localversion)), "The version should match the local version");
Assert.assertTrue(split.contains("url=false-url")); assertTrue(split.contains("url=false-url"), "The false-url should be shown in the changeset tag");
Assert.assertTrue(split.contains("maxadd=20")); assertTrue(split.contains("maxadd=20"), "The maxadd should be 20");
BBox tBBox = new BBox(1, 0, 0, 1); BBox tBBox = new BBox(1, 0, 0, 1);
MainApplication.getLayerManager() MainApplication.getLayerManager()
@ -110,10 +113,11 @@ public class MapWithAIUploadHookTest {
tags.clear(); tags.clear();
hook.modifyChangesetTags(tags); hook.modifyChangesetTags(tags);
split = Arrays.asList(tags.get("mapwithai:options").split(";")); split = Arrays.asList(tags.get("mapwithai:options").split(";"));
Assert.assertEquals(4, split.size()); assertEquals(4, split.size(), "There should be four ; in mapwithai:options");
Assert.assertTrue(split.contains("version=".concat(info.localversion))); assertTrue(split.contains("version=".concat(info.localversion)), "The version should match the local version");
Assert.assertTrue(split.contains("url=false-url")); assertTrue(split.contains("url=false-url"), "The false-url should be shown in the changeset tag");
Assert.assertTrue(split.contains("maxadd=20")); assertTrue(split.contains("maxadd=20"), "The maxadd should be 20");
Assert.assertTrue(split.contains("task=".concat(tBBox.toStringCSV(",")))); assertTrue(split.contains("task=".concat(tBBox.toStringCSV(","))),
"There should be a task in the mapwithai:options");
} }
} }

Wyświetl plik

@ -2,11 +2,12 @@
package org.openstreetmap.josm.plugins.mapwithai.commands; package org.openstreetmap.josm.plugins.mapwithai.commands;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
@ -39,23 +40,23 @@ public class AddNodeToWayCommandTest {
@Test @Test
public void testAddNodeToWay() { public void testAddNodeToWay() {
command.executeCommand(); command.executeCommand();
Assert.assertEquals(3, way.getNodesCount()); assertEquals(3, way.getNodesCount(), "A node should have been added to the way");
command.undoCommand(); command.undoCommand();
Assert.assertEquals(2, way.getNodesCount()); assertEquals(2, way.getNodesCount(), "The way should no longer be modified");
command = new AddNodeToWayCommand(toAdd, way, way.lastNode(), way.firstNode()); command = new AddNodeToWayCommand(toAdd, way, way.lastNode(), way.firstNode());
command.executeCommand(); command.executeCommand();
Assert.assertEquals(3, way.getNodesCount()); assertEquals(3, way.getNodesCount(), "A node should have been added to the way");
command.undoCommand(); command.undoCommand();
Assert.assertEquals(2, way.getNodesCount()); assertEquals(2, way.getNodesCount(), "The way should no longer be modified");
} }
@Test @Test
public void testDescription() { public void testDescription() {
Assert.assertNotNull(command.getDescriptionText()); assertNotNull(command.getDescriptionText(), "The command should have a description");
} }
@Test @Test
@ -64,9 +65,9 @@ public class AddNodeToWayCommandTest {
final List<OsmPrimitive> modified = new ArrayList<>(); final List<OsmPrimitive> modified = new ArrayList<>();
final List<OsmPrimitive> deleted = new ArrayList<>(); final List<OsmPrimitive> deleted = new ArrayList<>();
command.fillModifiedData(modified, deleted, added); command.fillModifiedData(modified, deleted, added);
Assert.assertTrue(deleted.isEmpty()); assertTrue(deleted.isEmpty(), "Nothing should have been deleted");
Assert.assertTrue(added.isEmpty()); assertTrue(added.isEmpty(), "Nothing should have been added");
Assert.assertEquals(2, modified.size()); assertEquals(2, modified.size(), "The way should have been modified, node is included in count");
} }
@Test @Test

Wyświetl plik

@ -2,13 +2,17 @@
package org.openstreetmap.josm.plugins.mapwithai.commands; package org.openstreetmap.josm.plugins.mapwithai.commands;
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options; import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
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.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import org.junit.After; import org.junit.After;
import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
@ -74,42 +78,43 @@ public class CreateConnectionsCommandTest {
Collections.singleton(node3)); Collections.singleton(node3));
createConnections.executeCommand(); createConnections.executeCommand();
Assert.assertFalse(dataSet.isModified()); assertFalse(dataSet.isModified(), "DataSet shouldn't be modified yet");
createConnections.undoCommand(); createConnections.undoCommand();
Assert.assertFalse(dataSet.isModified()); assertFalse(dataSet.isModified(), "DataSet shouldn't be modified yet");
node3.put(ConnectedCommand.CONN_KEY, node3.put(ConnectedCommand.CONN_KEY,
"w" + way.getUniqueId() + ",n" + node1.getUniqueId() + ",n" + node2.getUniqueId()); "w" + way.getUniqueId() + ",n" + node1.getUniqueId() + ",n" + node2.getUniqueId());
createConnections = new CreateConnectionsCommand(dataSet, Collections.singleton(node3)); createConnections = new CreateConnectionsCommand(dataSet, Collections.singleton(node3));
createConnections.executeCommand(); createConnections.executeCommand();
Assert.assertTrue(dataSet.isModified()); assertTrue(dataSet.isModified(), "DataSet should be modified");
Assert.assertEquals(3, way.getNodesCount()); assertEquals(3, way.getNodesCount(), "The way should have three nodes");
Assert.assertFalse(node3.hasKey(ConnectedCommand.CONN_KEY)); assertFalse(node3.hasKey(ConnectedCommand.CONN_KEY), "There should be no conn key");
createConnections.fillModifiedData(modified, deleted, added); createConnections.fillModifiedData(modified, deleted, added);
Assert.assertEquals(3, modified.size()); // 3 since we remove the key from the node assertEquals(3, modified.size(),
Assert.assertTrue(deleted.isEmpty()); "There should be three modifications (the connecting way, the node, and the node again for key removal)");
Assert.assertTrue(added.isEmpty()); assertTrue(deleted.isEmpty(), "Nothing has been deleted");
assertTrue(added.isEmpty(), "Nothing has been added");
createConnections.undoCommand(); createConnections.undoCommand();
Assert.assertFalse(dataSet.isModified()); assertFalse(dataSet.isModified(), "DataSet is no longer modified");
Assert.assertEquals(2, way.getNodesCount()); assertEquals(2, way.getNodesCount(), "The way should have two nodes again");
Assert.assertTrue(node3.hasKey(ConnectedCommand.CONN_KEY)); assertTrue(node3.hasKey(ConnectedCommand.CONN_KEY), "The conn key should exist again");
dupe.put(DuplicateCommand.DUPE_KEY, "n" + node1.getUniqueId()); dupe.put(DuplicateCommand.DUPE_KEY, "n" + node1.getUniqueId());
createConnections = new CreateConnectionsCommand(dataSet, Collections.singleton(dupe)); createConnections = new CreateConnectionsCommand(dataSet, Collections.singleton(dupe));
createConnections.executeCommand(); createConnections.executeCommand();
Assert.assertTrue(dataSet.isModified()); assertTrue(dataSet.isModified(), "The DataSet should be modified");
Assert.assertEquals(2, way.getNodesCount()); assertEquals(2, way.getNodesCount(), "The way should have two nodes");
Assert.assertFalse(node1.hasKey(DuplicateCommand.DUPE_KEY)); assertFalse(node1.hasKey(DuplicateCommand.DUPE_KEY), "There should no longer be a dupe key");
modified.clear(); modified.clear();
createConnections.fillModifiedData(modified, deleted, added); createConnections.fillModifiedData(modified, deleted, added);
Assert.assertEquals(2, modified.size()); assertEquals(2, modified.size(), "We removed a node and modified a way");
Assert.assertTrue(deleted.isEmpty()); assertTrue(deleted.isEmpty(), "Nothing was truly deleted (the dupe node doesn't count)");
Assert.assertTrue(added.isEmpty()); assertTrue(added.isEmpty(), "Nothing was added");
createConnections.undoCommand(); createConnections.undoCommand();
Assert.assertFalse(node1.hasKey(DuplicateCommand.DUPE_KEY)); assertFalse(node1.hasKey(DuplicateCommand.DUPE_KEY), "The original node should not have the dupe key");
Assert.assertTrue(dupe.hasKey(DuplicateCommand.DUPE_KEY)); assertTrue(dupe.hasKey(DuplicateCommand.DUPE_KEY), "The dupe node should have the dupe key");
Assert.assertFalse(dataSet.isModified()); assertFalse(dataSet.isModified(), "The DataSet is no longer modified");
Assert.assertEquals(2, way.getNodesCount()); assertEquals(2, way.getNodesCount(), "The way still has two nodes");
} }
/** /**
@ -118,32 +123,32 @@ public class CreateConnectionsCommandTest {
*/ */
@Test @Test
public void testAddNodesToWay() { public void testAddNodesToWay() {
final Node node1 = new Node(new LatLon(0, 0)); final Node wayNode1 = new Node(new LatLon(0, 0));
final Node node2 = new Node(new LatLon(1, 0)); final Node wayNode2 = new Node(new LatLon(1, 0));
final Node node3 = new Node(new LatLon(0.5, 0)); final Node toAddNode = new Node(new LatLon(0.5, 0));
final Way way = TestUtils.newWay("highway=residential", node1, node2); final Way way = TestUtils.newWay("highway=residential", wayNode1, wayNode2);
new DataSet(node1, node2, node3, way); new DataSet(wayNode1, wayNode2, toAddNode, way);
Command addNodeToWayCommand = ConnectedCommand.addNodesToWay(node3, way, node1, node2); Command addNodeToWayCommand = ConnectedCommand.addNodesToWay(toAddNode, way, wayNode1, wayNode2);
Assert.assertEquals(2, way.getNodesCount()); assertEquals(2, way.getNodesCount(), "The way should still have 2 nodes");
addNodeToWayCommand.executeCommand(); addNodeToWayCommand.executeCommand();
Assert.assertEquals(3, way.getNodesCount()); assertEquals(3, way.getNodesCount(), "The way should now have 3 nodes");
addNodeToWayCommand.undoCommand(); addNodeToWayCommand.undoCommand();
Assert.assertEquals(2, way.getNodesCount()); assertEquals(2, way.getNodesCount(), "The way should be back to having 2 nodes");
node2.setCoor(new LatLon(1, 0.1)); wayNode2.setCoor(new LatLon(1, 0.1));
addNodeToWayCommand = ConnectedCommand.addNodesToWay(node3, way, node1, node2); addNodeToWayCommand = ConnectedCommand.addNodesToWay(toAddNode, way, wayNode1, wayNode2);
Assert.assertNull(addNodeToWayCommand); assertNull(addNodeToWayCommand, "There shouldn't be a command to for a node that is a fair distance away");
node2.setCoor(new LatLon(1, 0.01)); wayNode2.setCoor(new LatLon(1, 0.01));
addNodeToWayCommand = ConnectedCommand.addNodesToWay(node3, way, node1, node2); addNodeToWayCommand = ConnectedCommand.addNodesToWay(toAddNode, way, wayNode1, wayNode2);
Assert.assertNull(addNodeToWayCommand); assertNull(addNodeToWayCommand, "There shouldn't be a command to for a node that is a fair distance away");
node2.setCoor(new LatLon(1, 0.00008)); wayNode2.setCoor(new LatLon(1, 0.00008));
addNodeToWayCommand = ConnectedCommand.addNodesToWay(node3, way, node1, node2); addNodeToWayCommand = ConnectedCommand.addNodesToWay(toAddNode, way, wayNode1, wayNode2);
addNodeToWayCommand.executeCommand(); addNodeToWayCommand.executeCommand();
Assert.assertEquals(3, way.getNodesCount()); assertEquals(3, way.getNodesCount(), "The way should have 3 nodes now");
addNodeToWayCommand.undoCommand(); addNodeToWayCommand.undoCommand();
Assert.assertEquals(2, way.getNodesCount()); assertEquals(2, way.getNodesCount(), "The way should now have 2 nodes");
} }
/** /**
@ -156,12 +161,13 @@ public class CreateConnectionsCommandTest {
new DataSet(node1, node2); new DataSet(node1, node2);
final Command replaceNodeCommand = DuplicateCommand.replaceNode(node1, node2); final Command replaceNodeCommand = DuplicateCommand.replaceNode(node1, node2);
replaceNodeCommand.executeCommand(); replaceNodeCommand.executeCommand();
Assert.assertTrue(node1.isDeleted()); assertTrue(node1.isDeleted(), "The node should not exist anymore");
replaceNodeCommand.undoCommand(); replaceNodeCommand.undoCommand();
Assert.assertFalse(node1.isDeleted()); assertFalse(node1.isDeleted(), "The node should exist again");
node2.setCoor(new LatLon(0.1, 0.1)); node2.setCoor(new LatLon(0.1, 0.1));
Assert.assertNull(DuplicateCommand.replaceNode(node1, node2)); assertNull(DuplicateCommand.replaceNode(node1, node2),
"There should not be a command for nodes with a large distance");
} }
/** /**
@ -175,12 +181,14 @@ public class CreateConnectionsCommandTest {
Command replaceNodeCommand = CreateConnectionsCommand.createConnections(dataSet, Collections.singleton(node1)); Command replaceNodeCommand = CreateConnectionsCommand.createConnections(dataSet, Collections.singleton(node1));
replaceNodeCommand.executeCommand(); replaceNodeCommand.executeCommand();
Assert.assertEquals(1, dataSet.allNonDeletedPrimitives().size()); assertEquals(1, dataSet.allNonDeletedPrimitives().size(), "There should be one primitive left");
Assert.assertNotNull(dataSet.getPrimitiveById(6146500887L, OsmPrimitiveType.NODE)); assertNotNull(dataSet.getPrimitiveById(6146500887L, OsmPrimitiveType.NODE),
"The OSM primitive should be the remaining primitive");
replaceNodeCommand.undoCommand(); replaceNodeCommand.undoCommand();
Assert.assertEquals(2, dataSet.allNonDeletedPrimitives().size()); // We don't roll back downloaded data assertEquals(2, dataSet.allNonDeletedPrimitives().size(), "We don't roll back downloaded data");
Assert.assertNotNull(dataSet.getPrimitiveById(6146500887L, OsmPrimitiveType.NODE)); assertNotNull(dataSet.getPrimitiveById(6146500887L, OsmPrimitiveType.NODE),
"We don't roll back downloaded data");
node1.setCoor(new LatLon(39.067399, -108.5608433)); node1.setCoor(new LatLon(39.067399, -108.5608433));
node1.put(DuplicateCommand.DUPE_KEY, "n6151680832"); node1.put(DuplicateCommand.DUPE_KEY, "n6151680832");
@ -189,12 +197,13 @@ public class CreateConnectionsCommandTest {
replaceNodeCommand = CreateConnectionsCommand.createConnections(dataSet, Collections.singleton(node1)); replaceNodeCommand = CreateConnectionsCommand.createConnections(dataSet, Collections.singleton(node1));
replaceNodeCommand.executeCommand(); replaceNodeCommand.executeCommand();
Assert.assertEquals(2, dataSet.allNonDeletedPrimitives().size()); assertEquals(2, dataSet.allNonDeletedPrimitives().size(), "The dupe node no longer matches with the OSM node");
Assert.assertNotNull(dataSet.getPrimitiveById(6146500887L, OsmPrimitiveType.NODE)); assertNotNull(dataSet.getPrimitiveById(6146500887L, OsmPrimitiveType.NODE), "The OSM node should still exist");
replaceNodeCommand.undoCommand(); replaceNodeCommand.undoCommand();
Assert.assertEquals(3, dataSet.allNonDeletedPrimitives().size()); // We don't roll back downloaded data assertEquals(3, dataSet.allNonDeletedPrimitives().size(), "We don't roll back downloaded data");
Assert.assertNotNull(dataSet.getPrimitiveById(6146500887L, OsmPrimitiveType.NODE)); assertNotNull(dataSet.getPrimitiveById(6146500887L, OsmPrimitiveType.NODE),
"We don't roll back downloaded data");
} }
@ -204,7 +213,7 @@ public class CreateConnectionsCommandTest {
@Test @Test
public void testGetDescriptionText() { public void testGetDescriptionText() {
final String text = new CreateConnectionsCommand(new DataSet(), Collections.emptyList()).getDescriptionText(); final String text = new CreateConnectionsCommand(new DataSet(), Collections.emptyList()).getDescriptionText();
Assert.assertNotNull(text); assertNotNull(text, "There should be a description for the command");
Assert.assertFalse(text.isEmpty()); assertFalse(text.isEmpty(), "The description should not be an empty string");
} }
} }

Wyświetl plik

@ -1,9 +1,11 @@
// License: GPL. For details, see LICENSE file. // License: GPL. For details, see LICENSE file.
package org.openstreetmap.josm.plugins.mapwithai.commands; package org.openstreetmap.josm.plugins.mapwithai.commands;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.Collections; import java.util.Collections;
import org.junit.Assert;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.openstreetmap.josm.TestUtils; import org.openstreetmap.josm.TestUtils;
@ -11,7 +13,6 @@ import org.openstreetmap.josm.data.coor.LatLon;
import org.openstreetmap.josm.data.osm.DataSet; import org.openstreetmap.josm.data.osm.DataSet;
import org.openstreetmap.josm.data.osm.Node; import org.openstreetmap.josm.data.osm.Node;
import org.openstreetmap.josm.data.osm.Way; import org.openstreetmap.josm.data.osm.Way;
import org.openstreetmap.josm.plugins.mapwithai.commands.DeletePrimitivesCommand;
import org.openstreetmap.josm.testutils.JOSMTestRules; import org.openstreetmap.josm.testutils.JOSMTestRules;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
@ -29,48 +30,46 @@ public class DeletePrimitivesCommandTest {
way1.getNodes().forEach(node -> ds.addPrimitive(node)); way1.getNodes().forEach(node -> ds.addPrimitive(node));
ds.addPrimitive(way1); ds.addPrimitive(way1);
Assert.assertTrue(ds.containsWay(way1));
DeletePrimitivesCommand delete = new DeletePrimitivesCommand(ds, Collections.singleton(way1)); DeletePrimitivesCommand delete = new DeletePrimitivesCommand(ds, Collections.singleton(way1));
delete.executeCommand(); delete.executeCommand();
Assert.assertTrue(way1.isDeleted()); assertTrue(way1.isDeleted(), "The way should be deleted");
Assert.assertEquals(0, ds.allNonDeletedPrimitives().size()); assertEquals(0, ds.allNonDeletedPrimitives().size(), "There should be no non-deleted primitives");
delete.undoCommand(); delete.undoCommand();
Assert.assertTrue(ds.containsWay(way1)); assertTrue(ds.containsWay(way1), "The DataSet should contain way1");
Assert.assertEquals(3, ds.allNonDeletedPrimitives().size()); assertEquals(3, ds.allNonDeletedPrimitives().size(), "There should be three non-deleted primitives");
final Node tNode = new Node(new LatLon(0.1, 0.1)); final Node tNode = new Node(new LatLon(0.1, 0.1));
ds.addPrimitive(tNode); ds.addPrimitive(tNode);
Assert.assertEquals(4, ds.allNonDeletedPrimitives().size());
delete.executeCommand(); delete.executeCommand();
Assert.assertTrue(way1.isDeleted()); assertTrue(way1.isDeleted(), "The way should be deleted");
Assert.assertEquals(1, ds.allNonDeletedPrimitives().size()); assertEquals(1, ds.allNonDeletedPrimitives().size(), "Non-relevant objects should not be affected");
delete.undoCommand(); delete.undoCommand();
Assert.assertEquals(4, ds.allNonDeletedPrimitives().size()); assertEquals(4, ds.allNonDeletedPrimitives().size(), "The DataSet should be as it was");
way1.firstNode().put("highway", "stop"); way1.firstNode().put("highway", "stop");
delete.executeCommand(); delete.executeCommand();
Assert.assertTrue(way1.isDeleted()); assertTrue(way1.isDeleted(), "The way should be deleted");
Assert.assertEquals(2, ds.allNonDeletedPrimitives().size()); assertEquals(2, ds.allNonDeletedPrimitives().size(), "Objects with their own keys should remain");
delete.undoCommand(); delete.undoCommand();
Assert.assertTrue(way1.firstNode().hasKey("highway")); assertTrue(way1.firstNode().hasKey("highway"), "Objects should not lose their keys");
delete = new DeletePrimitivesCommand(ds, Collections.singleton(way1), true); delete = new DeletePrimitivesCommand(ds, Collections.singleton(way1), true);
delete.executeCommand(); delete.executeCommand();
Assert.assertTrue(way1.isDeleted()); assertTrue(way1.isDeleted(), "The way should be deleted");
Assert.assertEquals(1, ds.allNonDeletedPrimitives().size()); assertEquals(1, ds.allNonDeletedPrimitives().size(),
"All nodes in the way not in another way should be removed");
delete.undoCommand(); delete.undoCommand();
Assert.assertEquals(4, ds.allNonDeletedPrimitives().size()); assertEquals(4, ds.allNonDeletedPrimitives().size(), "The DataSet should be as it was");
Assert.assertTrue(way1.firstNode().hasKey("highway")); assertTrue(way1.firstNode().hasKey("highway"), "Objects should not lose their keys");
} }
} }

Wyświetl plik

@ -2,13 +2,17 @@
package org.openstreetmap.josm.plugins.mapwithai.commands; package org.openstreetmap.josm.plugins.mapwithai.commands;
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options; import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
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.assertNotNull; 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.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import org.junit.After; import org.junit.After;
import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
@ -69,28 +73,27 @@ public class MapWithAIAddComandTest {
} }
MapWithAIAddCommand command = new MapWithAIAddCommand(ds1, ds2, Arrays.asList(way1, way2)); MapWithAIAddCommand command = new MapWithAIAddCommand(ds1, ds2, Arrays.asList(way1, way2));
command.executeCommand(); command.executeCommand();
Assert.assertNotNull(ds2.getPrimitiveById(way1)); for (Way way : Arrays.asList(way1, way2)) {
Assert.assertNotNull(ds2.getPrimitiveById(way1.firstNode())); assertNotNull(ds2.getPrimitiveById(way), "DataSet should still contain object");
Assert.assertNotNull(ds2.getPrimitiveById(way1.lastNode())); assertNotNull(ds2.getPrimitiveById(way.firstNode()), "DataSet should still contain object");
Assert.assertTrue(way1.isDeleted()); assertNotNull(ds2.getPrimitiveById(way.lastNode()), "DataSet should still contain object");
Assert.assertNotNull(ds2.getPrimitiveById(way2)); assertTrue(way.isDeleted(), "The way should be deleted");
Assert.assertNotNull(ds2.getPrimitiveById(way2.firstNode())); }
Assert.assertNotNull(ds2.getPrimitiveById(way2.lastNode()));
Assert.assertTrue(way2.isDeleted());
Assert.assertNull(ds2.getPrimitiveById(way3)); assertNull(ds2.getPrimitiveById(way3), "DataSet should not yet have way3");
command = new MapWithAIAddCommand(ds1, ds2, Arrays.asList(way3)); command = new MapWithAIAddCommand(ds1, ds2, Arrays.asList(way3));
command.executeCommand(); command.executeCommand();
Assert.assertNotNull(ds2.getPrimitiveById(way3)); assertNotNull(ds2.getPrimitiveById(way3), "DataSet should still contain object");
Assert.assertNotNull(ds2.getPrimitiveById(way3.firstNode())); assertNotNull(ds2.getPrimitiveById(way3.firstNode()), "DataSet should still contain object");
Assert.assertNotNull(ds2.getPrimitiveById(way3.lastNode())); assertNotNull(ds2.getPrimitiveById(way3.lastNode()), "DataSet should still contain object");
Assert.assertTrue(way3.isDeleted()); assertTrue(way3.isDeleted(), "The way should be deleted");
command.undoCommand(); command.undoCommand();
Assert.assertNull(ds2.getPrimitiveById(way3)); assertNull(ds2.getPrimitiveById(way3), "DataSet should no longer contain object");
Assert.assertNull(ds2.getPrimitiveById(way3.firstNode())); assertNull(ds2.getPrimitiveById(way3.firstNode()), "DataSet should no longer contain object");
Assert.assertNull(ds2.getPrimitiveById(way3.lastNode())); assertNull(ds2.getPrimitiveById(way3.lastNode()), "DataSet should no longer contain object");
Assert.assertFalse(ds1.getPrimitiveById(way3).isDeleted()); assertFalse(ds1.getPrimitiveById(way3).isDeleted(),
"The way should no longer be deleted in its original DataSet");
} }
@Test @Test
@ -109,8 +112,8 @@ public class MapWithAIAddComandTest {
ds1.addPrimitive(way2); ds1.addPrimitive(way2);
ds1.addPrimitive(way1); ds1.addPrimitive(way1);
MapWithAIAddCommand.createConnections(ds1, Collections.singletonList(way2.firstNode())).executeCommand(); MapWithAIAddCommand.createConnections(ds1, Collections.singletonList(way2.firstNode())).executeCommand();
Assert.assertEquals(3, way1.getNodesCount()); assertEquals(3, way1.getNodesCount(), "The way should now have three nodes");
Assert.assertFalse(way1.isFirstLastNode(way2.firstNode())); assertFalse(way1.isFirstLastNode(way2.firstNode()), "The ways should be connected");
final Way way3 = TestUtils.newWay(HIGHWAY_RESIDENTIAL, new Node(new LatLon(0, 0)), final Way way3 = TestUtils.newWay(HIGHWAY_RESIDENTIAL, new Node(new LatLon(0, 0)),
new Node(new LatLon(-0.1, -0.1))); new Node(new LatLon(-0.1, -0.1)));
@ -119,9 +122,9 @@ public class MapWithAIAddComandTest {
ds1.addPrimitive(way3); ds1.addPrimitive(way3);
final Node way3Node1 = way3.firstNode(); final Node way3Node1 = way3.firstNode();
MapWithAIAddCommand.createConnections(ds1, Collections.singletonList(way3.firstNode())).executeCommand(); MapWithAIAddCommand.createConnections(ds1, Collections.singletonList(way3.firstNode())).executeCommand();
Assert.assertNotEquals(way3Node1, way3.firstNode()); assertNotEquals(way3Node1, way3.firstNode(), "The original first node should no longer be the first node");
Assert.assertEquals(way1.firstNode(), way3.firstNode()); assertEquals(way1.firstNode(), way3.firstNode(), "way1 and way3 should have the same first nodes");
Assert.assertTrue(way3Node1.isDeleted()); assertTrue(way3Node1.isDeleted(), "way3 should be deleted");
} }
@Test @Test
@ -138,28 +141,27 @@ public class MapWithAIAddComandTest {
mapWithAIData.addPrimitive(way1); mapWithAIData.addPrimitive(way1);
mapWithAIData.setSelected(way1); mapWithAIData.setSelected(way1);
Assert.assertEquals(3, osmData.allNonDeletedPrimitives().size());
Assert.assertEquals(3, mapWithAIData.allNonDeletedPrimitives().size());
MapWithAIAddCommand command = new MapWithAIAddCommand(mapWithAIData, osmData, mapWithAIData.getSelected()); MapWithAIAddCommand command = new MapWithAIAddCommand(mapWithAIData, osmData, mapWithAIData.getSelected());
command.executeCommand(); command.executeCommand();
Assert.assertEquals(6, osmData.allNonDeletedPrimitives().size()); assertEquals(6, osmData.allNonDeletedPrimitives().size(), "All primitives should now be in osmData");
Assert.assertTrue(mapWithAIData.allNonDeletedPrimitives().isEmpty()); assertTrue(mapWithAIData.allNonDeletedPrimitives().isEmpty(),
"There should be no remaining non-deleted primitives");
command.undoCommand(); command.undoCommand();
Assert.assertEquals(3, osmData.allNonDeletedPrimitives().size()); assertEquals(3, osmData.allNonDeletedPrimitives().size(), "The DataSet should be in its original state");
Assert.assertEquals(3, mapWithAIData.allNonDeletedPrimitives().size()); assertEquals(3, mapWithAIData.allNonDeletedPrimitives().size(), "The DataSet should be in its original state");
final Tag dupe = new Tag("dupe", "n".concat(Long.toString(way2.lastNode().getUniqueId()))); final Tag dupe = new Tag("dupe", "n".concat(Long.toString(way2.lastNode().getUniqueId())));
way1.lastNode().put(dupe); way1.lastNode().put(dupe);
command = new MapWithAIAddCommand(mapWithAIData, osmData, mapWithAIData.getSelected()); command = new MapWithAIAddCommand(mapWithAIData, osmData, mapWithAIData.getSelected());
command.executeCommand(); command.executeCommand();
Assert.assertEquals(5, osmData.allNonDeletedPrimitives().size()); assertEquals(5, osmData.allNonDeletedPrimitives().size(), "All primitives should now be in osmData");
Assert.assertTrue(mapWithAIData.allNonDeletedPrimitives().isEmpty()); assertTrue(mapWithAIData.allNonDeletedPrimitives().isEmpty(),
"There should be no remaining non-deleted primitives");
command.undoCommand(); command.undoCommand();
Assert.assertEquals(3, osmData.allNonDeletedPrimitives().size()); assertEquals(3, osmData.allNonDeletedPrimitives().size(), "The DataSet should be in its original state");
Assert.assertEquals(3, mapWithAIData.allNonDeletedPrimitives().size()); assertEquals(3, mapWithAIData.allNonDeletedPrimitives().size(), "The DataSet should be in its original state");
} }
@Test @Test
@ -178,12 +180,12 @@ public class MapWithAIAddComandTest {
UndoRedoHandler.getInstance().add(new MoveCommand(tNode, LatLon.ZERO)); UndoRedoHandler.getInstance().add(new MoveCommand(tNode, LatLon.ZERO));
Assert.assertTrue(UndoRedoHandler.getInstance().getRedoCommands().isEmpty()); assertTrue(UndoRedoHandler.getInstance().getRedoCommands().isEmpty(), "There shouldn't be any redo commands");
Assert.assertEquals(2, UndoRedoHandler.getInstance().getUndoCommands().size()); assertEquals(2, UndoRedoHandler.getInstance().getUndoCommands().size(), "There should be two undo commands");
UndoRedoHandler.getInstance().undo(UndoRedoHandler.getInstance().getUndoCommands().size()); UndoRedoHandler.getInstance().undo(UndoRedoHandler.getInstance().getUndoCommands().size());
Assert.assertTrue(UndoRedoHandler.getInstance().getUndoCommands().isEmpty()); assertTrue(UndoRedoHandler.getInstance().getUndoCommands().isEmpty(), "There should be no undo commands");
Assert.assertEquals(2, UndoRedoHandler.getInstance().getRedoCommands().size()); assertEquals(2, UndoRedoHandler.getInstance().getRedoCommands().size(), "There should be two redo commands");
UndoRedoHandler.getInstance().redo(UndoRedoHandler.getInstance().getRedoCommands().size()); UndoRedoHandler.getInstance().redo(UndoRedoHandler.getInstance().getRedoCommands().size());
UndoRedoHandler.getInstance().undo(UndoRedoHandler.getInstance().getUndoCommands().size()); UndoRedoHandler.getInstance().undo(UndoRedoHandler.getInstance().getUndoCommands().size());