Skip to content

Commit 49db7f9

Browse files
author
Langston Smith
authored
Adding additional tests to files related to coordinate shifting (#936)
* initial additions * adjustment
1 parent 58b8d00 commit 49db7f9

7 files changed

Lines changed: 55 additions & 17 deletions

File tree

services-core/src/test/java/com/mapbox/core/TestUtils.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
package com.mapbox.core;
22

3-
import static java.nio.charset.StandardCharsets.UTF_8;
4-
import static org.junit.Assert.assertThat;
5-
import static org.junit.Assert.assertTrue;
6-
73
import com.google.gson.JsonParser;
4+
85
import org.hamcrest.Matchers;
96

107
import java.io.ByteArrayInputStream;
@@ -16,6 +13,11 @@
1613
import java.io.Serializable;
1714
import java.util.Scanner;
1815

16+
import static java.nio.charset.StandardCharsets.UTF_8;
17+
import static org.junit.Assert.assertEquals;
18+
import static org.junit.Assert.assertThat;
19+
import static org.junit.Assert.assertTrue;
20+
1921
public class TestUtils {
2022

2123
public static final double DELTA = 1E-10;

services-geojson/src/main/java/com/mapbox/geojson/gson/CoordinateTypeAdapter.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import com.google.gson.TypeAdapter;
44
import com.google.gson.stream.JsonReader;
55
import com.google.gson.stream.JsonWriter;
6-
76
import com.mapbox.geojson.shifter.CoordinateShifterManager;
87
import com.mapbox.geojson.utils.GeoJsonUtils;
98

services-geojson/src/test/java/com/mapbox/geojson/PointTest.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,19 @@ public void hasAltitude_returnsTrueWhenAltitudeIsPresent() throws Exception {
4242
}
4343

4444
@Test
45-
public void altitude_doesReturnCorrectValue() throws Exception {
46-
Point point = Point.fromLngLat(1.0, 2.0, 5.0);
45+
public void altitude_doesReturnCorrectValueFromDoubleArray() throws Exception {
46+
double[] coords = new double[] {1.0, 2.0, 5.0};
47+
Point point = Point.fromLngLat(coords);
4748
assertEquals(5, point.altitude(), DELTA);
4849
}
4950

51+
@Test
52+
public void point_isNullWithWrongLengthDoubleArray() throws Exception {
53+
double[] coords = new double[] {1.0};
54+
Point point = Point.fromLngLat(coords);
55+
assertNull(point);
56+
}
57+
5058
@Test
5159
public void longitude_doesReturnCorrectValue() throws Exception {
5260
Point point = Point.fromLngLat(1.0, 2.0, 5.0);

services-geojson/src/test/java/com/mapbox/geojson/gson/PointSerializerTest.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,35 @@
44
import com.mapbox.core.TestUtils;
55
import com.mapbox.geojson.BoundingBox;
66
import com.mapbox.geojson.Point;
7+
78
import org.junit.Test;
89

10+
import static org.junit.Assert.assertEquals;
11+
912
public class PointSerializerTest extends TestUtils {
1013

1114
private static final String POINT_FIXTURE = "sample-point.json";
1215
private static final String POINT_WITH_BBOX_FIXTURE = "sample-point-with-bbox.json";
13-
private static final String POINT_WITH_ALTITUDE_FIXTURE = "sample-point-with-altitude.json";
16+
private static final String POINT_WITH_ALTITUDE_AND_BBOX_FIXTURE = "sample-point-with-altitude-and-bbox.json";
17+
private static final String POINT_WITH_ALTITUDE_NO_BBOX_FIXTURE = "sample-point-with-altitude-no-bbox.json";
18+
19+
@Test
20+
public void point_hasAltitudeValueNoBoundingBox() throws Exception {
21+
Point point = Point.fromLngLat(100, 0, 200);
22+
compareJson(loadJsonFixture(POINT_WITH_ALTITUDE_NO_BBOX_FIXTURE), point.toJson());
23+
}
24+
25+
@Test
26+
public void point_hasAltitudeValueNoBoundingBoxAltCheck() throws Exception {
27+
Point point = Point.fromLngLat(100, 0, 200);
28+
assertEquals(200, point.altitude(), 0);
29+
}
1430

1531
@Test
16-
public void point_hasAltitudeValue() throws Exception {
32+
public void point_hasAltitudeValueWithBoundingBox() throws Exception {
1733
Point point = Point.fromLngLat(100, 0, 200,
1834
BoundingBox.fromLngLats(-100, -10, 100, 100, 10, 200));
19-
compareJson(loadJsonFixture(POINT_WITH_ALTITUDE_FIXTURE), point.toJson());
35+
compareJson(loadJsonFixture(POINT_WITH_ALTITUDE_AND_BBOX_FIXTURE), point.toJson());
2036
}
2137

2238
@Test

services-geojson/src/test/java/com/mapbox/geojson/shifter/ShifterTest.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,17 @@
55
import com.mapbox.geojson.LineString;
66
import com.mapbox.geojson.Point;
77

8-
import static com.mapbox.core.TestUtils.DELTA;
9-
import static org.junit.Assert.assertNotNull;
10-
import static org.junit.Assert.assertEquals;
11-
import static org.junit.Assert.assertThat;
12-
138
import org.hamcrest.Matchers;
149
import org.junit.Test;
1510

16-
import java.lang.reflect.Array;
1711
import java.util.ArrayList;
1812
import java.util.Arrays;
1913
import java.util.List;
2014

15+
import static org.junit.Assert.assertEquals;
16+
import static org.junit.Assert.assertNotNull;
17+
import static org.junit.Assert.assertThat;
18+
2119
public class ShifterTest {
2220

2321
static class TestCoordinateShifter implements CoordinateShifter {
@@ -48,7 +46,14 @@ public List<Double> unshiftPoint(List<Double> coordinates) {
4846
return Arrays.asList(coordinates.get(0) - 3,
4947
coordinates.get(1) - 5);
5048
}
51-
};
49+
}
50+
51+
@Test
52+
public void basic_coordinate_shifter_manager_creation() throws Exception {
53+
CoordinateShifterManager coordinateShifterManager = new CoordinateShifterManager();
54+
assertNotNull(coordinateShifterManager);
55+
}
56+
5257

5358
@Test
5459
public void point_basic_shift() throws Exception {

services-geojson/src/test/resources/sample-point-with-altitude.json renamed to services-geojson/src/test/resources/sample-point-with-altitude-and-bbox.json

File renamed without changes.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"type": "Point",
3+
"coordinates": [
4+
100,
5+
0,
6+
200
7+
]
8+
}

0 commit comments

Comments
 (0)