Changeset 14015 in josm


Ignore:
Timestamp:
2018-07-08T02:42:00+02:00 (8 months ago)
Author:
Don-vip
Message:

add unit tests on nominatim area name resolution

Location:
trunk
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/io/OverpassDownloadReader.java

    r13682 r14015  
    1313import java.util.Arrays;
    1414import java.util.EnumMap;
     15import java.util.List;
    1516import java.util.Locale;
    1617import java.util.Map;
     
    281282
    282283    private static SearchResult searchName(String area) throws IOException {
    283         return NameFinder.queryNominatim(area).stream().filter(
     284        return searchName(NameFinder.queryNominatim(area));
     285    }
     286
     287    static SearchResult searchName(List<SearchResult> results) {
     288        return results.stream().filter(
    284289                x -> !OsmPrimitiveType.NODE.equals(x.getOsmId().getType())).iterator().next();
    285290    }
     
    292297        idOffset.put(OsmPrimitiveType.RELATION, 3_600_000_000L);
    293298        final PrimitiveId osmId = searchName(area).getOsmId();
     299        Logging.debug("Area '{0}' resolved to {1}", area, osmId);
    294300        return String.format("area(%d)", osmId.getUniqueId() + idOffset.get(osmId.getType()));
    295301    }
  • trunk/test/unit/org/openstreetmap/josm/io/OverpassDownloadReaderTest.java

    r13337 r14015  
    1111import static org.junit.Assert.assertTrue;
    1212
     13import java.io.StringReader;
    1314import java.time.LocalDateTime;
    1415import java.util.regex.Matcher;
     
    217218                "out body;"));
    218219    }
     220
     221    /**
     222     * Unit test of {@link OverpassDownloadReader#searchName(java.util.List)}
     223     * @throws Exception if an error occurs
     224     */
     225    @Test
     226    public void testSearchName() throws Exception {
     227        try (StringReader reader = new StringReader(NameFinderTest.SAMPLE)) {
     228            assertEquals(1942586L,
     229                    OverpassDownloadReader.searchName(NameFinder.parseSearchResults(reader)).getOsmId().getUniqueId());
     230        }
     231    }
    219232}
Note: See TracChangeset for help on using the changeset viewer.