Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions services-core/src/test/java/com/mapbox/core/TestUtils.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package com.mapbox.core;

import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;

import com.google.gson.JsonParser;

import org.hamcrest.Matchers;

import java.io.ByteArrayInputStream;
Expand All @@ -16,6 +13,11 @@
import java.io.Serializable;
import java.util.Scanner;

import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;

public class TestUtils {

public static final double DELTA = 1E-10;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.google.gson.TypeAdapter;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;

import com.mapbox.geojson.shifter.CoordinateShifterManager;
import com.mapbox.geojson.utils.GeoJsonUtils;

Expand Down
12 changes: 10 additions & 2 deletions services-geojson/src/test/java/com/mapbox/geojson/PointTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,19 @@ public void hasAltitude_returnsTrueWhenAltitudeIsPresent() throws Exception {
}

@Test
public void altitude_doesReturnCorrectValue() throws Exception {
Point point = Point.fromLngLat(1.0, 2.0, 5.0);
public void altitude_doesReturnCorrectValueFromDoubleArray() throws Exception {
double[] coords = new double[] {1.0, 2.0, 5.0};
Point point = Point.fromLngLat(coords);
assertEquals(5, point.altitude(), DELTA);
}

@Test
public void point_isNullWithWrongLengthDoubleArray() throws Exception {
double[] coords = new double[] {1.0};
Point point = Point.fromLngLat(coords);
assertNull(point);
}

@Test
public void longitude_doesReturnCorrectValue() throws Exception {
Point point = Point.fromLngLat(1.0, 2.0, 5.0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,35 @@
import com.mapbox.core.TestUtils;
import com.mapbox.geojson.BoundingBox;
import com.mapbox.geojson.Point;

import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class PointSerializerTest extends TestUtils {

private static final String POINT_FIXTURE = "sample-point.json";
private static final String POINT_WITH_BBOX_FIXTURE = "sample-point-with-bbox.json";
private static final String POINT_WITH_ALTITUDE_FIXTURE = "sample-point-with-altitude.json";
private static final String POINT_WITH_ALTITUDE_AND_BBOX_FIXTURE = "sample-point-with-altitude-and-bbox.json";
private static final String POINT_WITH_ALTITUDE_NO_BBOX_FIXTURE = "sample-point-with-altitude-no-bbox.json";

@Test
public void point_hasAltitudeValueNoBoundingBox() throws Exception {
Point point = Point.fromLngLat(100, 0, 200);
compareJson(loadJsonFixture(POINT_WITH_ALTITUDE_NO_BBOX_FIXTURE), point.toJson());
}

@Test
public void point_hasAltitudeValueNoBoundingBoxAltCheck() throws Exception {
Point point = Point.fromLngLat(100, 0, 200);
assertEquals(200, point.altitude(), 0);
}

@Test
public void point_hasAltitudeValue() throws Exception {
public void point_hasAltitudeValueWithBoundingBox() throws Exception {
Point point = Point.fromLngLat(100, 0, 200,
BoundingBox.fromLngLats(-100, -10, 100, 100, 10, 200));
compareJson(loadJsonFixture(POINT_WITH_ALTITUDE_FIXTURE), point.toJson());
compareJson(loadJsonFixture(POINT_WITH_ALTITUDE_AND_BBOX_FIXTURE), point.toJson());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,17 @@
import com.mapbox.geojson.LineString;
import com.mapbox.geojson.Point;

import static com.mapbox.core.TestUtils.DELTA;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;

import org.hamcrest.Matchers;
import org.junit.Test;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;

public class ShifterTest {

static class TestCoordinateShifter implements CoordinateShifter {
Expand Down Expand Up @@ -48,7 +46,14 @@ public List<Double> unshiftPoint(List<Double> coordinates) {
return Arrays.asList(coordinates.get(0) - 3,
coordinates.get(1) - 5);
}
};
}

@Test
public void basic_coordinate_shifter_manager_creation() throws Exception {
CoordinateShifterManager coordinateShifterManager = new CoordinateShifterManager();
assertNotNull(coordinateShifterManager);
}


@Test
public void point_basic_shift() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"type": "Point",
"coordinates": [
100,
0,
200
]
}