Fix broken tests

This was caused by changed behavior in various classes. Some were broken
due to changing facts (for example, Canada now has highways, as does
most of the rest of the world).

Signed-off-by: Taylor Smock <taylor.smock@kaart.com>
pull/1/head
Taylor Smock 2020-04-01 08:28:56 -06:00
rodzic 48475c7c14
commit 16fcc489de
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 625F6A74A3E4311A
4 zmienionych plików z 28 dodań i 32 usunięć

Wyświetl plik

@ -168,19 +168,20 @@ public final class MapWithAIDataUtils {
if ((realBBoxes.size() < TOO_MANY_BBOXES) || confirmBigDownload(realBBoxes)) {
final PleaseWaitProgressMonitor monitor = new PleaseWaitProgressMonitor();
monitor.beginTask(tr("Downloading {0} Data", MapWithAIPlugin.NAME), realBounds.size());
realBounds.parallelStream().forEach(bound -> MapWithAIPreferenceHelper.getMapWithAIUrl()
.parallelStream().filter(i -> i.getUrl() != null && !i.getUrl().trim().isEmpty()).forEach(i -> {
BoundingBoxMapWithAIDownloader downloader = new BoundingBoxMapWithAIDownloader(bound, i,
DetectTaskingManagerUtils.hasTaskingManagerLayer());
try {
DataSet ds = downloader.parseOsm(monitor.createSubTaskMonitor(1, false));
synchronized (MapWithAIDataUtils.class) {
dataSet.mergeFrom(ds);
}
} catch (OsmTransferException e) {
Logging.error(e);
}
}));
realBounds.parallelStream()
.forEach(bound -> new ArrayList<>(MapWithAIPreferenceHelper.getMapWithAIUrl()).parallelStream()
.filter(i -> i.getUrl() != null && !i.getUrl().trim().isEmpty()).forEach(i -> {
BoundingBoxMapWithAIDownloader downloader = new BoundingBoxMapWithAIDownloader(
bound, i, DetectTaskingManagerUtils.hasTaskingManagerLayer());
try {
DataSet ds = downloader.parseOsm(monitor.createSubTaskMonitor(1, false));
synchronized (MapWithAIDataUtils.class) {
dataSet.mergeFrom(ds);
}
} catch (OsmTransferException e) {
Logging.error(e);
}
}));
monitor.finishTask();
monitor.close();
}

Wyświetl plik

@ -38,7 +38,7 @@ import org.openstreetmap.josm.tools.Utils;
public class MapWithAILayerInfo {
/** List of all usable layers */
private final List<MapWithAIInfo> layers = new ArrayList<>();
private final List<MapWithAIInfo> layers = Collections.synchronizedList(new ArrayList<>());
/** List of layer ids of all usable layers */
private final Map<String, MapWithAIInfo> layerIds = new HashMap<>();
/** List of all available default layers */
@ -378,10 +378,12 @@ public class MapWithAILayerInfo {
/**
* Save the list of imagery entries to preferences.
*/
public void save() {
public synchronized void save() {
List<MapWithAIPreferenceEntry> entries = new ArrayList<>();
for (MapWithAIInfo info : layers) {
entries.add(new MapWithAIPreferenceEntry(info));
synchronized (layers) {
for (MapWithAIInfo info : layers) {
entries.add(new MapWithAIPreferenceEntry(info));
}
}
StructUtils.putListOfStructs(Config.getPref(), CONFIG_PREFIX + "entries", entries,
MapWithAIPreferenceEntry.class);

Wyświetl plik

@ -71,10 +71,10 @@ public class MapWithAIAvailabilityTest {
"The US should have highway data");
assertTrue(DataAvailability.getDataTypes(new LatLon(40, -100)).getOrDefault("building", false),
"The US should have building data");
assertFalse(DataAvailability.getDataTypes(new LatLon(45.424722, -75.695)).getOrDefault("highway", false),
"Canada does not yet have highway data");
assertTrue(DataAvailability.getDataTypes(new LatLon(45.424722, -75.695)).getOrDefault("building", false),
"Canada does have building data");
assertFalse(DataAvailability.getDataTypes(new LatLon(71.67, -42.85)).getOrDefault("highway", false),
"Denmark should not have highway data");
assertFalse(DataAvailability.getDataTypes(new LatLon(71.67, -42.85)).getOrDefault("building", false),
"Denmark does not have building data");
assertTrue(DataAvailability.getDataTypes(new LatLon(19.433333, -99.133333)).getOrDefault("highway", false),
"Mexico has highway data");
assertFalse(DataAvailability.getDataTypes(new LatLon(19.433333, -99.133333)).getOrDefault("building", false),

Wyświetl plik

@ -19,34 +19,27 @@ import org.openstreetmap.josm.gui.download.DownloadSettings;
import org.openstreetmap.josm.plugins.mapwithai.MapWithAIPlugin;
import org.openstreetmap.josm.plugins.mapwithai.backend.MapWithAIDataUtils;
import org.openstreetmap.josm.plugins.mapwithai.backend.MapWithAIPreferenceHelper;
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAILayerInfo;
import org.openstreetmap.josm.plugins.mapwithai.gui.preferences.MapWithAILayerInfoTest;
import org.openstreetmap.josm.testutils.JOSMTestRules;
import com.github.tomakehurst.wiremock.WireMockServer;
public class MapWithAIDownloadReaderTest {
@Rule
public JOSMTestRules rules = new JOSMTestRules().projection();
public JOSMTestRules rules = new JOSMTestRules().projection().territories();
WireMockServer wireMock = new WireMockServer(options().usingFilesUnderDirectory("test/resources/wiremock"));
@Before
public void setUp() {
wireMock.start();
MapWithAILayerInfo.instance.getLayers().forEach(i -> i.setUrl(getDefaultMapWithAIAPIForTest(i.getUrl())));
MapWithAILayerInfoTest.setupMapWithAILayerInfo(wireMock);
}
@After
public void tearDown() {
wireMock.stop();
}
private String getDefaultMapWithAIAPIForTest(String url) {
return getDefaultMapWithAIAPIForTest(url, "https://www.mapwith.ai");
}
private String getDefaultMapWithAIAPIForTest(String url, String wireMockReplace) {
return url.replace(wireMockReplace, wireMock.baseUrl());
MapWithAILayerInfoTest.resetMapWithAILayerInfo();
}
@Test