Add test for already added elements and remove an unused variable

Signed-off-by: Taylor Smock <taylor.smock@kaart.com>
pull/1/head
Taylor Smock 2019-12-17 15:41:15 -07:00
rodzic d1dce41156
commit ac885c04bb
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 625F6A74A3E4311A
5 zmienionych plików z 42 dodań i 9 usunięć

Wyświetl plik

@ -1,3 +1,4 @@
// License: GPL. For details, see LICENSE file.
package org.openstreetmap.josm.plugins.mapwithai.backend;
import java.io.IOException;

Wyświetl plik

@ -1,3 +1,4 @@
// License: GPL. For details, see LICENSE file.
package org.openstreetmap.josm.plugins.mapwithai.backend;
import static org.openstreetmap.josm.tools.I18n.tr;

Wyświetl plik

@ -59,7 +59,6 @@ public class GetDataRunnable extends RecursiveTask<DataSet> {
private static final int MAX_NUMBER_OF_BBOXES_TO_PROCESS = 1;
private static final String SERVER_ID_KEY = "server_id";
private static final int DEFAULT_TIMEOUT = 50_000; // 50 seconds
private static final double ARTIFACT_ANGLE = 0.1745; // 10 degrees in radians

Wyświetl plik

@ -3,6 +3,7 @@ package org.openstreetmap.josm.plugins.mapwithai.backend;
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
import static org.junit.Assume.assumeTrue;
import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
@ -27,6 +28,8 @@ import org.openstreetmap.josm.data.osm.Node;
import org.openstreetmap.josm.data.osm.Way;
import org.openstreetmap.josm.data.osm.WaySegment;
import org.openstreetmap.josm.data.projection.ProjectionRegistry;
import org.openstreetmap.josm.gui.MainApplication;
import org.openstreetmap.josm.gui.layer.OsmDataLayer;
import org.openstreetmap.josm.testutils.JOSMTestRules;
import org.openstreetmap.josm.tools.Geometry;
@ -42,7 +45,7 @@ public class GetDataRunnableTest {
public void setUp() {
wireMock.start();
MapWithAIPreferenceHelper.setMapWithAIURLs(MapWithAIPreferenceHelper.getMapWithAIURLs().stream().map(map -> {
map.put("url", getDefaultMapWithAIAPIForTest(
map.put("url", getDefaultMapWithAIAPIForTest(wireMock,
map.getOrDefault("url", MapWithAIPreferenceHelper.DEFAULT_MAPWITHAI_API)));
return map;
}).collect(Collectors.toList()));
@ -53,11 +56,11 @@ public class GetDataRunnableTest {
wireMock.stop();
}
private String getDefaultMapWithAIAPIForTest(String url) {
return getDefaultMapWithAIAPIForTest(url, "https://www.facebook.com");
public static String getDefaultMapWithAIAPIForTest(WireMockServer wireMock, String url) {
return getDefaultMapWithAIAPIForTest(wireMock, url, "https://www.facebook.com");
}
private String getDefaultMapWithAIAPIForTest(String url, String wireMockReplace) {
public static String getDefaultMapWithAIAPIForTest(WireMockServer wireMock, String url, String wireMockReplace) {
return url.replace(wireMockReplace, wireMock.baseUrl());
}
@ -121,4 +124,29 @@ public class GetDataRunnableTest {
assertFalse(ds.isEmpty());
assertFalse(ds.allNonDeletedPrimitives().isEmpty());
}
@Test
public void testAlreadyAddedElements() {
Way addedWay = TestUtils.newWay("", new Node(new LatLon(0, 0)), new Node(new LatLon(1, 1)));
Way duplicateWay = TestUtils.newWay("", new Node(new LatLon(0, 0)), new Node(new LatLon(1, 1)));
Way nonDuplicateWay = TestUtils.newWay("", new Node(new LatLon(0, 0)), new Node(new LatLon(1, 2)));
DataSet osm = new DataSet();
addedWay.getNodes().forEach(osm::addPrimitive);
osm.addPrimitive(addedWay);
DataSet conflationDs = new DataSet();
for (Way way : Arrays.asList(duplicateWay, nonDuplicateWay)) {
way.getNodes().forEach(conflationDs::addPrimitive);
conflationDs.addPrimitive(way);
}
MainApplication.getLayerManager().addLayer(new OsmDataLayer(osm, "OSM Layer", null));
GetDataRunnable.removeAlreadyAddedData(conflationDs);
assertAll(() -> assertTrue(duplicateWay.isDeleted(), "The duplicate way should be deleted"),
() -> duplicateWay.getNodes()
.forEach(node -> assertTrue(node.isDeleted(), "The duplicate way nodes should be deleted")),
() -> assertFalse(nonDuplicateWay.isDeleted(), "The non-duplicate way should not be deleted"));
}
}

Wyświetl plik

@ -22,6 +22,7 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.openstreetmap.josm.TestUtils;
import org.openstreetmap.josm.data.Bounds;
import org.openstreetmap.josm.data.coor.LatLon;
import org.openstreetmap.josm.data.gpx.GpxData;
import org.openstreetmap.josm.data.gpx.WayPoint;
@ -117,10 +118,13 @@ public class MapWithAIDataUtilsTest {
}
public static BBox getTestBBox() {
final BBox testBBox = new BBox();
testBBox.add(new LatLon(39.0734162, -108.5707107));
testBBox.add(new LatLon(39.0738791, -108.5715723));
return testBBox;
return getTestBounds().toBBox();
}
public static Bounds getTestBounds() {
Bounds bound = new Bounds(39.0734162, -108.5707107);
bound.extend(39.0738791, -108.5715723);
return bound;
}
@Test