source: josm/trunk/test/unit/org/openstreetmap/josm/tools/OsmUrlToBoundsTest.java@ 8509

Last change on this file since 8509 was 8509, checked in by Don-vip, 9 years ago

fix many checkstyle violations

  • Property svn:eol-style set to native
File size: 3.8 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.tools;
3
4import org.junit.Assert;
5import org.junit.Test;
6import org.openstreetmap.josm.data.Bounds;
7
8/**
9 * Unit tests of {@link OsmUrlToBounds} class.
10*/
11public class OsmUrlToBoundsTest {
12 /**
13 * data for {@link #testParse}
14 */
15 private static final ParseTestItem[] parseTestData = {
16 new ParseTestItem("https://www.openstreetmap.org", null),
17 new ParseTestItem("https://www.openstreetmap.org/?bbox=-0.489,51.28,0.236,51.686",
18 new Bounds(51.28, -0.489, 51.686, 0.236)),
19 new ParseTestItem("https://www.openstreetmap.org/?minlon=-0.489&minlat=51.28&maxlon=0.236&maxlat=51.686",
20 new Bounds(51.28, -0.489, 51.686, 0.236)),
21 new ParseTestItem("https://www.openstreetmap.org/?maxlat=51.686&maxlon=0.236&minlat=51.28&minlon=-0.489",
22 new Bounds(51.28, -0.489, 51.686, 0.236)),
23 new ParseTestItem("https://www.openstreetmap.org/?zoom=17&lat=51.71873&lon=8.76164",
24 OsmUrlToBounds.positionToBounds(51.71873, 8.76164, 17)),
25 new ParseTestItem("https://www.openstreetmap.org/?lon=8.76164&lat=51.71873&zoom=17&foo",
26 OsmUrlToBounds.positionToBounds(51.71873, 8.76164, 17)),
27 new ParseTestItem("https://www.openstreetmap.org/?mlon=8.76164&mlat=51.71873",
28 OsmUrlToBounds.positionToBounds(51.71873, 8.76164, 18)),
29 new ParseTestItem("http://osm.org/go/euulwp",
30 OsmUrlToBounds.positionToBounds(51.48262023925781, -0.29937744140625, 8)),
31 new ParseTestItem("https://www.openstreetmap.org/#map=17/51.71873/8.76164",
32 OsmUrlToBounds.positionToBounds(51.71873, 8.76164, 17)),
33 new ParseTestItem("https://www.openstreetmap.org/#map=17/51.71873/8.76164&layers=CN",
34 OsmUrlToBounds.positionToBounds(51.71873, 8.76164, 17)),
35 new ParseTestItem("https%3A%2F%2Fwww.openstreetmap.org%2F%23map%3D16%2F51.71873%2F8.76164",
36 OsmUrlToBounds.positionToBounds(51.71873, 8.76164, 16)),
37 new ParseTestItem("https%3A%2F%2Fwww.openstreetmap.org%2F%23map%3D16%2F51.71873%2F8.76164%26layers%3DCN",
38 OsmUrlToBounds.positionToBounds(51.71873, 8.76164, 16)),
39 new ParseTestItem("https://www.openstreetmap.org/?note=26325#map=18/40.86215/-75.75020",
40 OsmUrlToBounds.positionToBounds(40.86215, -75.75020, 18)),
41 new ParseTestItem("https://www.openstreetmap.org/?note=26325#map=18/40.86215/-75.75020&layers=N",
42 OsmUrlToBounds.positionToBounds(40.86215, -75.75020, 18)),
43 new ParseTestItem("https://www.openstreetmap.org/?mlat=51.5&mlon=-0.01#map=10/51.4831/-0.1270",
44 OsmUrlToBounds.positionToBounds(51.4831, -0.1270, 10)),
45 new ParseTestItem("https://www.openstreetmap.org/?mlat=51.5&mlon=-0.01#map=10/51.4831/-0.3509&layers=T",
46 OsmUrlToBounds.positionToBounds(51.4831, -0.3509, 10)),
47 new ParseTestItem("https://www.openstreetmap.org/#map", null),
48 new ParseTestItem("https://www.openstreetmap.org/#map=foo", null),
49 new ParseTestItem("https://www.openstreetmap.org/#map=fooz/foolat/foolon", null)
50 };
51
52 private static class ParseTestItem {
53 public String url;
54 public Bounds bounds;
55
56 public ParseTestItem(String url, Bounds bounds) {
57 this.url = url;
58 this.bounds = bounds;
59 }
60 }
61
62 /**
63 * Test URL parsing
64 */
65 @Test
66 public void testParse() {
67 for (ParseTestItem item : parseTestData) {
68 Bounds bounds = null;
69 try {
70 bounds = OsmUrlToBounds.parse(item.url);
71 } catch (IllegalArgumentException e) {
72 // Ignore. check if bounds is null after
73 }
74 Assert.assertEquals(item.url, item.bounds, bounds);
75 }
76 }
77
78}
Note: See TracBrowser for help on using the repository browser.