Ignore:
Timestamp:
2020-02-28T21:42:52+01:00 (4 years ago)
Author:
Don-vip
Message:

see #18772 - better error message, add non-regression tests

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/tools/TerritoriesTest.java

    r14138 r15952  
    22package org.openstreetmap.josm.tools;
    33
     4import static java.util.Collections.singleton;
    45import static org.junit.Assert.assertTrue;
     6import static org.junit.jupiter.api.Assertions.assertEquals;
     7
     8import java.util.Arrays;
     9import java.util.HashSet;
     10import java.util.Map;
     11import java.util.Set;
     12import java.util.TreeMap;
    513
    614import org.junit.Rule;
    715import org.junit.Test;
     16import org.openstreetmap.josm.TestUtils;
    817import org.openstreetmap.josm.data.coor.LatLon;
    918import org.openstreetmap.josm.testutils.JOSMTestRules;
     
    4554        }
    4655    }
     56
     57    /**
     58     * Test of {@link Territories#initializeExternalData} - nominal case
     59     */
     60    @Test
     61    public void testTaginfoGeofabrik_nominal() {
     62        Map<String, TaginfoRegionalInstance> cache = new TreeMap<>();
     63        Territories.initializeExternalData(cache, "foo", TestUtils.getTestDataRoot() + "/taginfo/geofabrik-index-v1-nogeom.json");
     64        assertEquals(5, cache.size());
     65        checkTaginfoInstance(cache.get("AF"), singleton("AF"), "https://taginfo.geofabrik.de/asia/afghanistan/");
     66        checkTaginfoInstance(cache.get("AL"), singleton("AL"), "https://taginfo.geofabrik.de/europe/albania/");
     67        checkTaginfoInstance(cache.get("CA-AB"), singleton("CA-AB"), "https://taginfo.geofabrik.de/north-america/canada/alberta/");
     68        Set<String> israelAndPalestine = new HashSet<>(Arrays.asList("PS", "IL"));
     69        checkTaginfoInstance(cache.get("PS"), israelAndPalestine, "https://taginfo.geofabrik.de/asia/israel-and-palestine/");
     70        checkTaginfoInstance(cache.get("IL"), israelAndPalestine, "https://taginfo.geofabrik.de/asia/israel-and-palestine/");
     71    }
     72
     73    private static void checkTaginfoInstance(TaginfoRegionalInstance instance, Set<String> expectedIsoCodes, String expectedUrl) {
     74        assertEquals(expectedIsoCodes, instance.getIsoCodes());
     75        assertEquals("foo", instance.getSuffix());
     76        assertEquals(expectedUrl, instance.getUrl());
     77    }
     78
     79    /**
     80     * Test of {@link Territories#initializeExternalData} - broken contents
     81     */
     82    @Test
     83    public void testTaginfoGeofabrik_broken() {
     84        Map<String, TaginfoRegionalInstance> cache = new TreeMap<>();
     85        Logging.clearLastErrorAndWarnings();
     86        Territories.initializeExternalData(cache, "foo", TestUtils.getTestDataRoot() + "taginfo/geofabrik-index-v1-nogeom-broken.json");
     87        assertTrue(cache.isEmpty());
     88        assertEquals("W: Failed to parse external taginfo data at test/data/taginfo/geofabrik-index-v1-nogeom-broken.json: " +
     89                "Invalid token=EOF at (line no=3, column no=49, offset=97). Expected tokens are: " +
     90                "[CURLYOPEN, SQUAREOPEN, STRING, NUMBER, TRUE, FALSE, NULL, SQUARECLOSE]",
     91                Logging.getLastErrorAndWarnings().get(0));
     92    }
    4793}
Note: See TracChangeset for help on using the changeset viewer.