1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.tools;
|
---|
3 |
|
---|
4 | import static org.hamcrest.CoreMatchers.nullValue;
|
---|
5 | import static org.hamcrest.MatcherAssert.assertThat;
|
---|
6 | import static org.hamcrest.core.Is.is;
|
---|
7 | import static org.junit.jupiter.api.Assertions.assertThrows;
|
---|
8 |
|
---|
9 | import org.junit.jupiter.api.Test;
|
---|
10 |
|
---|
11 | /**
|
---|
12 | * Unit tests of {@link GeoUrlToBoundsTest} class.
|
---|
13 | */
|
---|
14 | class GeoUrlToBoundsTest {
|
---|
15 |
|
---|
16 | /**
|
---|
17 | * Tests parsing Geo URLs with the zoom specified.
|
---|
18 | */
|
---|
19 | @Test
|
---|
20 | void testParse() {
|
---|
21 | assertThat(
|
---|
22 | GeoUrlToBounds.parse("geo:12.34,56.78?z=9"),
|
---|
23 | is(OsmUrlToBounds.positionToBounds(12.34, 56.78, 9))
|
---|
24 | );
|
---|
25 | }
|
---|
26 |
|
---|
27 | /**
|
---|
28 | * Tests parsing Geo URLs without the zoom parameter.
|
---|
29 | */
|
---|
30 | @Test
|
---|
31 | void testParseWithoutZoom() {
|
---|
32 | assertThat(
|
---|
33 | GeoUrlToBounds.parse("geo:12.34,56.78"),
|
---|
34 | is(OsmUrlToBounds.positionToBounds(12.34, 56.78, 18))
|
---|
35 | );
|
---|
36 | assertThat(
|
---|
37 | GeoUrlToBounds.parse("geo:-37.786971,-122.399677"),
|
---|
38 | is(OsmUrlToBounds.positionToBounds(-37.786971, -122.399677, 18))
|
---|
39 | );
|
---|
40 | }
|
---|
41 |
|
---|
42 | /**
|
---|
43 | * Tests parsing Geo URLs with a CRS and/or uncertainty.
|
---|
44 | */
|
---|
45 | @Test
|
---|
46 | void testParseCrsUncertainty() {
|
---|
47 | assertThat(
|
---|
48 | GeoUrlToBounds.parse("geo:60.00000,17.000000;crs=wgs84"),
|
---|
49 | is(OsmUrlToBounds.positionToBounds(60.0, 17.0, 18))
|
---|
50 | );
|
---|
51 | assertThat(
|
---|
52 | GeoUrlToBounds.parse("geo:60.00000,17.000000;crs=wgs84;u=0"),
|
---|
53 | is(OsmUrlToBounds.positionToBounds(60.0, 17.0, 18))
|
---|
54 | );
|
---|
55 | assertThat(
|
---|
56 | GeoUrlToBounds.parse("geo:60.00000,17.000000;u=20"),
|
---|
57 | is(OsmUrlToBounds.positionToBounds(60.0, 17.0, 18))
|
---|
58 | );
|
---|
59 | }
|
---|
60 |
|
---|
61 | /**
|
---|
62 | * Tests parsing invalid Geo URL.
|
---|
63 | */
|
---|
64 | @Test
|
---|
65 | void testInvalid() {
|
---|
66 | assertThat(GeoUrlToBounds.parse("geo:foo"), nullValue());
|
---|
67 | assertThat(GeoUrlToBounds.parse("geo:foo,bar"), nullValue());
|
---|
68 | }
|
---|
69 |
|
---|
70 | /**
|
---|
71 | * Tests parsing null.
|
---|
72 | */
|
---|
73 | @Test
|
---|
74 | void testNull() {
|
---|
75 | assertThrows(IllegalArgumentException.class, () -> GeoUrlToBounds.parse(null));
|
---|
76 | }
|
---|
77 | }
|
---|