Ensure that we only try to convert to tags when an equals sign is present.

This fixes #90.

Signed-off-by: Taylor Smock <taylor.smock@kaart.com>
pull/1/head
Taylor Smock 2020-06-30 08:27:58 -06:00
rodzic 59f6ee8671
commit 786ee5f689
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 625F6A74A3E4311A
2 zmienionych plików z 16 dodań i 0 usunięć

Wyświetl plik

@ -66,6 +66,9 @@ public class GetDataRunnable extends RecursiveTask<DataSet> {
private static final int MAX_NUMBER_OF_BBOXES_TO_PROCESS = 1;
private static final String SERVER_ID_KEY = "current_id";
/** An equals sign (=) used for tag splitting */
private static final String EQUALS = "=";
private static final double ARTIFACT_ANGLE = 0.1745; // 10 degrees in radians
/**
@ -291,6 +294,7 @@ public class GetDataRunnable extends RecursiveTask<DataSet> {
*/
public static void replaceTags(DataSet dataSet) {
final Map<Tag, Tag> replaceTags = MapWithAIPreferenceHelper.getReplacementTags().entrySet().parallelStream()
.filter(entry -> entry.getKey().contains(EQUALS) && entry.getValue().contains(EQUALS))
.map(entry -> new Pair<>(Tag.ofString(entry.getKey()), Tag.ofString(entry.getValue())))
.collect(Collectors.toMap(pair -> pair.a, pair -> pair.b));
replaceTags(dataSet, replaceTags);

Wyświetl plik

@ -3,6 +3,7 @@ package org.openstreetmap.josm.plugins.mapwithai.backend;
import static org.junit.Assume.assumeTrue;
import static org.junit.jupiter.api.Assertions.assertAll;
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;
@ -134,4 +135,15 @@ public class GetDataRunnableTest {
.forEach(node -> assertTrue(node.isDeleted(), "The duplicate way nodes should be deleted")),
() -> assertFalse(nonDuplicateWay.isDeleted(), "The non-duplicate way should not be deleted"));
}
/**
* Non-regression test for <a
* href=https://gitlab.com/gokaart/JOSM_MapWithAI/-/issues/90>#90</a>
*/
@Test
public void testEmptyTagReplacement() {
MapWithAIPreferenceHelper.setReplacementTags(Collections.singletonMap("", ""));
DataSet ds = new DataSet();
assertDoesNotThrow(() -> GetDataRunnable.replaceTags(ds));
}
}