Changeset 16595 in josm


Ignore:
Timestamp:
2020-06-11T08:40:11+02:00 (8 weeks ago)
Author:
simon04
Message:

Add unit test for Territories.getRegionalTaginfoUrls

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/Territories.java

    r16552 r16595  
    188188
    189189    private static void initializeExternalData() {
     190        initializeExternalData("Geofabrik",
     191                Config.getUrls().getJOSMWebsite() + "/remote/geofabrik-index-v1-nogeom.json");
     192    }
     193
     194    static void initializeExternalData(String source, String path) {
    190195        taginfoGeofabrikCache = new TreeMap<>();
    191         initializeExternalData(taginfoGeofabrikCache, "Geofabrik",
    192                 Config.getUrls().getJOSMWebsite() + "/remote/geofabrik-index-v1-nogeom.json");
    193     }
    194 
    195     static void initializeExternalData(Map<String, TaginfoRegionalInstance> cache, String source, String path) {
    196196        try (CachedFile cf = new CachedFile(path); InputStream is = cf.getInputStream(); JsonParser json = Json.createParser(is)) {
    197197            while (json.hasNext()) {
     
    205205                            JsonArray iso2 = props.getJsonArray(ISO3166_2_LC);
    206206                            if (iso1 != null) {
    207                                 readExternalTaginfo(cache, taginfo, iso1, source);
     207                                readExternalTaginfo(taginfoGeofabrikCache, taginfo, iso1, source);
    208208                            } else if (iso2 != null) {
    209                                 readExternalTaginfo(cache, taginfo, iso2, source);
     209                                readExternalTaginfo(taginfoGeofabrikCache, taginfo, iso2, source);
    210210                            }
    211211                        })));
  • trunk/test/unit/org/openstreetmap/josm/tools/TerritoriesTest.java

    r16182 r16595  
    99import java.util.Arrays;
    1010import java.util.HashSet;
     11import java.util.List;
    1112import java.util.Map;
    1213import java.util.Set;
    13 import java.util.TreeMap;
    1414
    1515import org.junit.Rule;
     
    3535    /**
    3636     * Tests that {@code Territories} satisfies utility class criteria.
     37     *
    3738     * @throws ReflectiveOperationException if an error occurs
    3839     */
     
    6162    @Test
    6263    public void testTaginfoGeofabrik_nominal() {
    63         Map<String, TaginfoRegionalInstance> cache = new TreeMap<>();
    64         Territories.initializeExternalData(cache, "foo", TestUtils.getTestDataRoot() + "/taginfo/geofabrik-index-v1-nogeom.json");
     64        Territories.initializeExternalData("foo", TestUtils.getTestDataRoot() + "/taginfo/geofabrik-index-v1-nogeom.json");
     65        Map<String, TaginfoRegionalInstance> cache = Territories.taginfoGeofabrikCache;
    6566        assertEquals(5, cache.size());
    6667        checkTaginfoInstance(cache.get("AF"), singleton("AF"), "https://taginfo.geofabrik.de/asia/afghanistan/");
     
    7071        checkTaginfoInstance(cache.get("PS"), israelAndPalestine, "https://taginfo.geofabrik.de/asia/israel-and-palestine/");
    7172        checkTaginfoInstance(cache.get("IL"), israelAndPalestine, "https://taginfo.geofabrik.de/asia/israel-and-palestine/");
     73        List<TaginfoRegionalInstance> regionalTaginfo = Territories.getRegionalTaginfoUrls(new LatLon(41.3268733, 19.8187913));
     74        assertEquals(1, regionalTaginfo.size());
     75        checkTaginfoInstance(regionalTaginfo.iterator().next(), singleton("AL"), "https://taginfo.geofabrik.de/europe/albania/");
    7276    }
    7377
     
    8387    @Test
    8488    public void testTaginfoGeofabrik_broken() {
    85         Map<String, TaginfoRegionalInstance> cache = new TreeMap<>();
    8689        Logging.clearLastErrorAndWarnings();
    87         Territories.initializeExternalData(cache, "foo", TestUtils.getTestDataRoot() + "taginfo/geofabrik-index-v1-nogeom-broken.json");
     90        Territories.initializeExternalData("foo", TestUtils.getTestDataRoot() + "taginfo/geofabrik-index-v1-nogeom-broken.json");
     91        Map<String, TaginfoRegionalInstance> cache = Territories.taginfoGeofabrikCache;
    8892        assertTrue(cache.isEmpty());
    8993        String error = Logging.getLastErrorAndWarnings().get(0);
Note: See TracChangeset for help on using the changeset viewer.