From fea0fc13c735fc5fbebc4dcf8f4ba4748f059b54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=83=C2=A2=C3=82=C2=80=C3=82=C2=9Cosana=C3=83=C2=A2?= =?UTF-8?q?=C3=82=C2=80=C3=82=C2=9D?= Date: Tue, 19 Mar 2019 18:42:36 -0400 Subject: [PATCH] removed dependency of Turf library on services-core --- services-core/build.gradle | 4 - .../test/java/com/mapbox/core/TestUtils.java | 1 - .../api/directions/v5/models/LegStep.java | 4 +- services-geojson/build.gradle | 5 - .../com/mapbox/geojson/LineStringTest.java | 8 +- .../mapbox/geojson/MultiLineStringTest.java | 5 +- .../java/com/mapbox/geojson/TestUtils.java | 61 +++++++ .../geojson/utils/PolylineUtilsTest.java | 39 ++--- services-turf/build.gradle | 8 - .../java/com/mapbox/turf/TurfAssertions.java | 7 +- .../main/java/com/mapbox/turf/TurfMisc.java | 11 +- .../turf/models/LineIntersectsResult.java | 152 ++++++++++++++++-- .../test/java/com/mapbox/turf/TestUtils.java | 61 +++++++ .../com/mapbox/turf/TurfAssertionsTest.java | 1 - .../mapbox/turf/TurfClassificationTest.java | 1 - .../com/mapbox/turf/TurfConversionTest.java | 2 - .../java/com/mapbox/turf/TurfJoinsTest.java | 1 - .../com/mapbox/turf/TurfMeasurementTest.java | 1 - .../java/com/mapbox/turf/TurfMetaTest.java | 1 - .../java/com/mapbox/turf/TurfMiscTest.java | 1 - .../mapbox/turf/TurfTransformationTest.java | 1 - 21 files changed, 296 insertions(+), 79 deletions(-) create mode 100644 services-geojson/src/test/java/com/mapbox/geojson/TestUtils.java create mode 100644 services-turf/src/test/java/com/mapbox/turf/TestUtils.java diff --git a/services-core/build.gradle b/services-core/build.gradle index f0bca9a1e..13d415504 100644 --- a/services-core/build.gradle +++ b/services-core/build.gradle @@ -49,10 +49,6 @@ dependencies { // OkHttp api dependenciesList.okhttp3Logging - // AutoValue - compileOnly dependenciesList.autoValue - compileOnly dependenciesList.autoValueGson - // Test Dependencies testOutput sourceSets.test.output } \ No newline at end of file diff --git a/services-core/src/test/java/com/mapbox/core/TestUtils.java b/services-core/src/test/java/com/mapbox/core/TestUtils.java index ffb5b37b7..c68b27731 100644 --- a/services-core/src/test/java/com/mapbox/core/TestUtils.java +++ b/services-core/src/test/java/com/mapbox/core/TestUtils.java @@ -14,7 +14,6 @@ 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; diff --git a/services-directions/src/main/java/com/mapbox/api/directions/v5/models/LegStep.java b/services-directions/src/main/java/com/mapbox/api/directions/v5/models/LegStep.java index 17d629d77..0271f721d 100644 --- a/services-directions/src/main/java/com/mapbox/api/directions/v5/models/LegStep.java +++ b/services-directions/src/main/java/com/mapbox/api/directions/v5/models/LegStep.java @@ -65,8 +65,8 @@ public static Builder builder() { public abstract String name(); /** - * Any road designations associated with the road or path leading from this step's - * maneuver to the next step's maneuver. Optionally included, if data is available. + * Any road designations associated with the road or path leading from this step's + * maneuver to the next step's maneuver. Optionally included, if data is available. * If multiple road designations are associated with the road, they are separated by semicolons. * A road designation typically consists of an alphabetic network code (identifying the road type * or numbering system), a space or hyphen, and a route number. You should not assume that diff --git a/services-geojson/build.gradle b/services-geojson/build.gradle index 92a0596ee..bde176985 100644 --- a/services-geojson/build.gradle +++ b/services-geojson/build.gradle @@ -11,12 +11,7 @@ dependencies { // Annotations compileOnly dependenciesList.supportAnnotation - // AutoValue - compileOnly dependenciesList.autoValue - compileOnly dependenciesList.autoValueGson - // Test Dependencies testImplementation dependenciesList.okhttp3Mockwebserver testImplementation project(path: ':services-core', configuration: 'testOutput') - testImplementation project(":services-turf") } \ No newline at end of file diff --git a/services-geojson/src/test/java/com/mapbox/geojson/LineStringTest.java b/services-geojson/src/test/java/com/mapbox/geojson/LineStringTest.java index ad09c8618..0e6a8d3fc 100644 --- a/services-geojson/src/test/java/com/mapbox/geojson/LineStringTest.java +++ b/services-geojson/src/test/java/com/mapbox/geojson/LineStringTest.java @@ -5,9 +5,6 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; -import com.mapbox.core.TestUtils; -import com.mapbox.core.constants.Constants; - import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; @@ -20,6 +17,9 @@ public class LineStringTest extends TestUtils { private static final String SAMPLE_LINESTRING_FIXTURE = "sample-linestring.json"; + private static final int PRECISION_6 = 6; + private static final int PRECISION_5 = 5; + @Rule public ExpectedException thrown = ExpectedException.none(); @@ -40,7 +40,7 @@ public void fromLngLats_generatedFromMultipoint() throws Exception { points.add(Point.fromLngLat(4.0,8.0)); MultiPoint multiPoint = MultiPoint.fromLngLats(points); LineString lineString = LineString.fromLngLats(multiPoint); - assertEquals("_gayB_c`|@_wemJ_kbvD", lineString.toPolyline(Constants.PRECISION_6)); + assertEquals("_gayB_c`|@_wemJ_kbvD", lineString.toPolyline(PRECISION_6)); } @Test diff --git a/services-geojson/src/test/java/com/mapbox/geojson/MultiLineStringTest.java b/services-geojson/src/test/java/com/mapbox/geojson/MultiLineStringTest.java index 0c20169fa..d84f6fe38 100644 --- a/services-geojson/src/test/java/com/mapbox/geojson/MultiLineStringTest.java +++ b/services-geojson/src/test/java/com/mapbox/geojson/MultiLineStringTest.java @@ -5,8 +5,6 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; -import com.mapbox.core.TestUtils; - import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; @@ -19,6 +17,9 @@ public class MultiLineStringTest extends TestUtils { private static final String SAMPLE_MULTILINESTRING = "sample-multilinestring.json"; + private static final int PRECISION_6 = 6; + private static final int PRECISION_5 = 5; + @Rule public ExpectedException thrown = ExpectedException.none(); diff --git a/services-geojson/src/test/java/com/mapbox/geojson/TestUtils.java b/services-geojson/src/test/java/com/mapbox/geojson/TestUtils.java new file mode 100644 index 000000000..ca8982adb --- /dev/null +++ b/services-geojson/src/test/java/com/mapbox/geojson/TestUtils.java @@ -0,0 +1,61 @@ +package com.mapbox.geojson; + +import com.google.gson.JsonParser; + +import org.hamcrest.Matchers; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.Serializable; +import java.util.Scanner; + +import static java.nio.charset.StandardCharsets.UTF_8; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; + +public class TestUtils { + + public static final double DELTA = 1E-10; + public static final String ACCESS_TOKEN = "pk.XXX"; + + public void compareJson(String expectedJson, String actualJson) { + JsonParser parser = new JsonParser(); + assertThat(parser.parse(actualJson), Matchers.equalTo(parser.parse(expectedJson))); + } + + protected String loadJsonFixture(String filename) throws IOException { + ClassLoader classLoader = getClass().getClassLoader(); + InputStream inputStream = classLoader.getResourceAsStream(filename); + Scanner scanner = new Scanner(inputStream, UTF_8.name()).useDelimiter("\\A"); + return scanner.hasNext() ? scanner.next() : ""; + } + + public static byte[] serialize(T obj) + throws IOException { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + ObjectOutputStream oos = new ObjectOutputStream(baos); + oos.writeObject(obj); + oos.close(); + return baos.toByteArray(); + } + + public static T deserialize(byte[] bytes, Class cl) + throws IOException, ClassNotFoundException { + ByteArrayInputStream bais = new ByteArrayInputStream(bytes); + ObjectInputStream ois = new ObjectInputStream(bais); + Object object = ois.readObject(); + return cl.cast(object); + } + + /** + * Comes from Google Utils Test Case + */ + public static void expectNearNumber(double expected, double actual, double epsilon) { + assertTrue(String.format("Expected %f to be near %f", actual, expected), + Math.abs(expected - actual) <= epsilon); + } +} diff --git a/services-geojson/src/test/java/com/mapbox/geojson/utils/PolylineUtilsTest.java b/services-geojson/src/test/java/com/mapbox/geojson/utils/PolylineUtilsTest.java index 5e26e364e..e4261e90b 100644 --- a/services-geojson/src/test/java/com/mapbox/geojson/utils/PolylineUtilsTest.java +++ b/services-geojson/src/test/java/com/mapbox/geojson/utils/PolylineUtilsTest.java @@ -7,10 +7,10 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import com.mapbox.core.TestUtils; -import com.mapbox.core.constants.Constants; import com.mapbox.geojson.LineString; import com.mapbox.geojson.Point; +import com.mapbox.geojson.TestUtils; + import org.junit.Test; import java.io.IOException; @@ -20,6 +20,9 @@ public class PolylineUtilsTest extends TestUtils { + private static final int PRECISION_6 = 6; + private static final int PRECISION_5 = 5; + // Delta for Coordinates comparison private static final double DELTA = 0.000001; @@ -34,7 +37,7 @@ public class PolylineUtilsTest extends TestUtils { @Test public void testDecodePath() { - List latLngs = decode(TEST_LINE, Constants.PRECISION_5); + List latLngs = decode(TEST_LINE, PRECISION_5); int expectedLength = 21; assertEquals("Wrong length.", expectedLength, latLngs.size()); @@ -46,15 +49,15 @@ public void testDecodePath() { @Test public void testEncodePath5() { - List path = decode(TEST_LINE, Constants.PRECISION_5); - String encoded = encode(path, Constants.PRECISION_5); + List path = decode(TEST_LINE, PRECISION_5); + String encoded = encode(path, PRECISION_5); assertEquals(TEST_LINE, encoded); } @Test public void testDecodeEncodePath6() { - List path = decode(TEST_LINE6, Constants.PRECISION_6); - String encoded = encode(path, Constants.PRECISION_6); + List path = decode(TEST_LINE6, PRECISION_6); + String encoded = encode(path, PRECISION_6); assertEquals(TEST_LINE6, encoded); } @@ -65,8 +68,8 @@ public void testFromPolyline6() { Point.fromLngLat(2.2862036, 48.8267868), Point.fromLngLat(2.4, 48.9) ); - String encoded = encode(originalPath, Constants.PRECISION_6); - List path = LineString.fromPolyline(encoded, Constants.PRECISION_6).coordinates(); + String encoded = encode(originalPath, PRECISION_6); + List path = LineString.fromPolyline(encoded, PRECISION_6).coordinates(); assertEquals(originalPath.size(), path.size()); for (int i = 0; i < originalPath.size(); i++) { @@ -78,8 +81,8 @@ public void testFromPolyline6() { @Test public void testFromPolylineAndDecode() { - List path1 = LineString.fromPolyline(TEST_LINE6, Constants.PRECISION_6).coordinates(); - List path2 = decode(TEST_LINE6, Constants.PRECISION_6); + List path1 = LineString.fromPolyline(TEST_LINE6, PRECISION_6).coordinates(); + List path2 = decode(TEST_LINE6, PRECISION_6); assertEquals(path1.size(), path2.size()); for (int i = 0; i < path1.size(); i++) { @@ -95,8 +98,8 @@ public void testEncodeDecodePath6() { Point.fromLngLat(2.4, 48.9) ); - String encoded = encode(originalPath, Constants.PRECISION_6); - List path = decode(encoded, Constants.PRECISION_6); + String encoded = encode(originalPath, PRECISION_6); + List path = decode(encoded, PRECISION_6); assertEquals(originalPath.size(), path.size()); for (int i = 0; i < originalPath.size(); i++) { @@ -108,20 +111,20 @@ public void testEncodeDecodePath6() { @Test public void decode_neverReturnsNullButRatherAnEmptyList() throws Exception { - List path = decode("", Constants.PRECISION_5); + List path = decode("", PRECISION_5); assertNotNull(path); assertEquals(0, path.size()); } @Test public void encode_neverReturnsNull() throws Exception { - String encodedString = encode(new ArrayList(), Constants.PRECISION_6); + String encodedString = encode(new ArrayList(), PRECISION_6); assertNotNull(encodedString); } @Test public void simplify_neverReturnsNullButRatherAnEmptyList() throws Exception { - List simplifiedPath = simplify(new ArrayList(), Constants.PRECISION_6); + List simplifiedPath = simplify(new ArrayList(), PRECISION_6); assertNotNull(simplifiedPath); } @@ -130,14 +133,14 @@ public void simplify_returnSameListWhenListSizeIsLessThanOrEqualToTwo(){ final List path = new ArrayList<>(); path.add(Point.fromLngLat(0, 0)); path.add(Point.fromLngLat(10, 0)); - List simplifiedPath = simplify(path, Constants.PRECISION_6, true); + List simplifiedPath = simplify(path, PRECISION_6, true); assertTrue("Returned list is different from input list", path == simplifiedPath); } @Test public void simplify_withHighestQuality() throws IOException{ List path = createPointListFromResourceFile(SIMPLIFICATION_INPUT); - List simplifiedPath = simplify(path, Constants.PRECISION_5, true); + List simplifiedPath = simplify(path, PRECISION_5, true); List expectedSimplifiedPath = createPointListFromResourceFile(SIMPLIFICATION_EXPECTED_OUTPUT); assertTrue("Wrong number of points retained",simplifiedPath.size() == expectedSimplifiedPath.size()); int counter = 0; diff --git a/services-turf/build.gradle b/services-turf/build.gradle index 1df285c8d..dc74aab56 100644 --- a/services-turf/build.gradle +++ b/services-turf/build.gradle @@ -5,16 +5,8 @@ apply plugin: 'java-library' apply from: "../gradle/dependencies.gradle" dependencies { - api project(":services-core") api project(":services-geojson") // Annotations compileOnly dependenciesList.supportAnnotation - - // AutoValue - compileOnly dependenciesList.autoValue - compileOnly dependenciesList.autoValueGson - - // Test Dependencies - testImplementation project(path: ':services-core', configuration: 'testOutput') } \ No newline at end of file diff --git a/services-turf/src/main/java/com/mapbox/turf/TurfAssertions.java b/services-turf/src/main/java/com/mapbox/turf/TurfAssertions.java index 8c9a3f01a..df9ee0546 100644 --- a/services-turf/src/main/java/com/mapbox/turf/TurfAssertions.java +++ b/services-turf/src/main/java/com/mapbox/turf/TurfAssertions.java @@ -3,7 +3,6 @@ import com.mapbox.geojson.Feature; import com.mapbox.geojson.FeatureCollection; import com.mapbox.geojson.GeoJson; -import com.mapbox.core.utils.TextUtils; import com.mapbox.geojson.Point; /** @@ -43,7 +42,7 @@ public static Point getCoord(Feature obj) { * @since 1.2.0 */ public static void geojsonType(GeoJson value, String type, String name) { - if (TextUtils.isEmpty(type) || TextUtils.isEmpty(name)) { + if (type == null || type.length() == 0 || name == null || name.length() == 0) { throw new TurfException("Type and name required"); } if (value == null || !value.type().equals(type)) { @@ -63,7 +62,7 @@ public static void geojsonType(GeoJson value, String type, String name) { * @since 1.2.0 */ public static void featureOf(Feature feature, String type, String name) { - if (TextUtils.isEmpty(name)) { + if (name == null || name.length() == 0) { throw new TurfException(".featureOf() requires a name"); } if (feature == null || !feature.type().equals("Feature") || feature.geometry() == null) { @@ -87,7 +86,7 @@ public static void featureOf(Feature feature, String type, String name) { * @since 1.2.0 */ public static void collectionOf(FeatureCollection featureCollection, String type, String name) { - if (TextUtils.isEmpty(name)) { + if (name == null || name.length() == 0) { throw new TurfException("collectionOf() requires a name"); } if (featureCollection == null || !featureCollection.type().equals("FeatureCollection") diff --git a/services-turf/src/main/java/com/mapbox/turf/TurfMisc.java b/services-turf/src/main/java/com/mapbox/turf/TurfMisc.java index ff47e79d5..e109bb31d 100644 --- a/services-turf/src/main/java/com/mapbox/turf/TurfMisc.java +++ b/services-turf/src/main/java/com/mapbox/turf/TurfMisc.java @@ -1,7 +1,5 @@ package com.mapbox.turf; -import static com.mapbox.core.internal.Preconditions.checkNotNull; - import android.support.annotation.FloatRange; import android.support.annotation.NonNull; import com.mapbox.geojson.Feature; @@ -41,7 +39,9 @@ private TurfMisc() { @NonNull public static LineString lineSlice(@NonNull Point startPt, @NonNull Point stopPt, @NonNull Feature line) { - checkNotNull(line.geometry(), "Feature.geometry() == null"); + if (line.geometry() == null) { + throw new NullPointerException("Feature.geometry() == null"); + } if (!line.geometry().type().equals("LineString")) { throw new TurfException("input must be a LineString Feature or Geometry"); } @@ -115,8 +115,9 @@ public static LineString lineSliceAlong(@NonNull Feature line, @FloatRange(from = 0) double startDist, @FloatRange(from = 0) double stopDist, @NonNull @TurfConstants.TurfUnitCriteria String units) { - - checkNotNull(line.geometry(), "Feature.geometry() == null"); + if (line.geometry() == null) { + throw new NullPointerException("Feature.geometry() == null"); + } if (!line.geometry().type().equals("LineString")) { throw new TurfException("input must be a LineString Feature or Geometry"); } diff --git a/services-turf/src/main/java/com/mapbox/turf/models/LineIntersectsResult.java b/services-turf/src/main/java/com/mapbox/turf/models/LineIntersectsResult.java index c9e151f44..d2d049f7d 100644 --- a/services-turf/src/main/java/com/mapbox/turf/models/LineIntersectsResult.java +++ b/services-turf/src/main/java/com/mapbox/turf/models/LineIntersectsResult.java @@ -2,8 +2,6 @@ import android.support.annotation.Nullable; -import com.google.auto.value.AutoValue; - /** * if the lines intersect, the result contains the x and y of the intersection (treating the lines * as infinite) and booleans for whether line segment 1 or line segment 2 contain the point. @@ -11,8 +9,26 @@ * @see Good example of how this class works written in JavaScript * @since 1.2.0 */ -@AutoValue -public abstract class LineIntersectsResult { +public class LineIntersectsResult { + + private final Double horizontalIntersection; + + private final Double verticalIntersection; + + private final boolean onLine1; + + private final boolean onLine2; + + private LineIntersectsResult( + @Nullable Double horizontalIntersection, + @Nullable Double verticalIntersection, + boolean onLine1, + boolean onLine2) { + this.horizontalIntersection = horizontalIntersection; + this.verticalIntersection = verticalIntersection; + this.onLine1 = onLine1; + this.onLine2 = onLine2; + } /** * Builds a new instance of a lineIntersection. This class is mainly used internally for other @@ -22,7 +38,7 @@ public abstract class LineIntersectsResult { * @since 3.0.0 */ public static Builder builder() { - return new AutoValue_LineIntersectsResult.Builder(); + return new Builder(); } /** @@ -32,7 +48,10 @@ public static Builder builder() { * @since 1.2.0 */ @Nullable - public abstract Double horizontalIntersection(); + public Double horizontalIntersection() { + return horizontalIntersection; + } + /** * If the lines intersect, use this method to get the intersecting point {@code Y} value. @@ -41,7 +60,10 @@ public static Builder builder() { * @since 1.2.0 */ @Nullable - public abstract Double verticalIntersection(); + public Double verticalIntersection() { + return verticalIntersection; + } + /** * Determine if the intersecting point lands on line 1 or not. @@ -49,7 +71,9 @@ public static Builder builder() { * @return true if the intersecting point is located on line 1, otherwise false * @since 1.2.0 */ - public abstract boolean onLine1(); + public boolean onLine1() { + return onLine1; + } /** * Determine if the intersecting point lands on line 2 or not. @@ -57,7 +81,52 @@ public static Builder builder() { * @return true if the intersecting point is located on line 2, otherwise false * @since 1.2.0 */ - public abstract boolean onLine2(); + public boolean onLine2() { + return onLine2; + } + + @Override + public String toString() { + return "LineIntersectsResult{" + + "horizontalIntersection=" + horizontalIntersection + ", " + + "verticalIntersection=" + verticalIntersection + ", " + + "onLine1=" + onLine1 + ", " + + "onLine2=" + onLine2 + + "}"; + } + + @Override + public boolean equals(Object obj) { + if (obj == this) { + return true; + } + if (obj instanceof LineIntersectsResult) { + LineIntersectsResult that = (LineIntersectsResult) obj; + return ((this.horizontalIntersection == null) + ? (that.horizontalIntersection() == null) : + this.horizontalIntersection.equals(that.horizontalIntersection())) + && ((this.verticalIntersection == null) + ? (that.verticalIntersection() == null) : + this.verticalIntersection.equals(that.verticalIntersection())) + && (this.onLine1 == that.onLine1()) + && (this.onLine2 == that.onLine2()); + } + return false; + } + + @Override + public int hashCode() { + int hashCode = 1; + hashCode *= 1000003; + hashCode ^= (horizontalIntersection == null) ? 0 : horizontalIntersection.hashCode(); + hashCode *= 1000003; + hashCode ^= (verticalIntersection == null) ? 0 : verticalIntersection.hashCode(); + hashCode *= 1000003; + hashCode ^= onLine1 ? 1231 : 1237; + hashCode *= 1000003; + hashCode ^= onLine2 ? 1231 : 1237; + return hashCode; + } /** * Convert current instance values into another Builder to quickly change one or more values. @@ -65,7 +134,10 @@ public static Builder builder() { * @return a new instance of {@link LineIntersectsResult} using the newly defined values * @since 3.0.0 */ - public abstract Builder toBuilder(); + public Builder toBuilder() { + return new Builder(this); + } + /** * Build a new {@link LineIntersectsResult} instance and define its features by passing in @@ -73,8 +145,22 @@ public static Builder builder() { * * @since 3.0.0 */ - @AutoValue.Builder - public abstract static class Builder { + public static class Builder { + + private Double horizontalIntersection; + private Double verticalIntersection; + private Boolean onLine1 = false; + private Boolean onLine2 = false; + + Builder() { + } + + private Builder(LineIntersectsResult source) { + this.horizontalIntersection = source.horizontalIntersection(); + this.verticalIntersection = source.verticalIntersection(); + this.onLine1 = source.onLine1(); + this.onLine2 = source.onLine2(); + } /** * If the lines intersect, use this method to get the intersecting point {@code X} value. @@ -83,7 +169,10 @@ public abstract static class Builder { * @return the {@code X} value where the lines intersect * @since 3.0.0 */ - public abstract Builder horizontalIntersection(@Nullable Double horizontalIntersection); + public Builder horizontalIntersection(@Nullable Double horizontalIntersection) { + this.horizontalIntersection = horizontalIntersection; + return this; + } /** * If the lines intersect, use this method to get the intersecting point {@code Y} value. @@ -92,7 +181,11 @@ public abstract static class Builder { * @return the {@code Y} value where the lines intersect * @since 3.0.0 */ - public abstract Builder verticalIntersection(@Nullable Double verticalIntersection); + public Builder verticalIntersection(@Nullable Double verticalIntersection) { + this.verticalIntersection = verticalIntersection; + return this; + } + /** * Determine if the intersecting point lands on line 1 or not. @@ -101,7 +194,11 @@ public abstract static class Builder { * @return true if the intersecting point is located on line 1, otherwise false * @since 3.0.0 */ - public abstract Builder onLine1(boolean onLine1); + public Builder onLine1(boolean onLine1) { + this.onLine1 = onLine1; + return this; + } + /** * Determine if the intersecting point lands on line 2 or not. @@ -110,7 +207,11 @@ public abstract static class Builder { * @return true if the intersecting point is located on line 2, otherwise false * @since 3.0.0 */ - public abstract Builder onLine2(boolean onLine2); + public Builder onLine2(boolean onLine2) { + this.onLine2 = onLine2; + return this; + } + /** * Builds a new instance of a {@link LineIntersectsResult} class. @@ -118,6 +219,23 @@ public abstract static class Builder { * @return a new instance of {@link LineIntersectsResult} * @since 3.0.0 */ - public abstract LineIntersectsResult build(); + public LineIntersectsResult build() { + String missing = ""; + if (this.onLine1 == null) { + missing += " onLine1"; + } + if (this.onLine2 == null) { + missing += " onLine2"; + } + if (!missing.isEmpty()) { + throw new IllegalStateException("Missing required properties:" + missing); + } + return new LineIntersectsResult( + this.horizontalIntersection, + this.verticalIntersection, + this.onLine1, + this.onLine2); + } } + } diff --git a/services-turf/src/test/java/com/mapbox/turf/TestUtils.java b/services-turf/src/test/java/com/mapbox/turf/TestUtils.java new file mode 100644 index 000000000..c9f6b8e1f --- /dev/null +++ b/services-turf/src/test/java/com/mapbox/turf/TestUtils.java @@ -0,0 +1,61 @@ +package com.mapbox.turf; + +import com.google.gson.JsonParser; + +import org.hamcrest.Matchers; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.Serializable; +import java.util.Scanner; + +import static java.nio.charset.StandardCharsets.UTF_8; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; + +public class TestUtils { + + public static final double DELTA = 1E-10; + public static final String ACCESS_TOKEN = "pk.XXX"; + + public void compareJson(String expectedJson, String actualJson) { + JsonParser parser = new JsonParser(); + assertThat(parser.parse(actualJson), Matchers.equalTo(parser.parse(expectedJson))); + } + + protected String loadJsonFixture(String filename) throws IOException { + ClassLoader classLoader = getClass().getClassLoader(); + InputStream inputStream = classLoader.getResourceAsStream(filename); + Scanner scanner = new Scanner(inputStream, UTF_8.name()).useDelimiter("\\A"); + return scanner.hasNext() ? scanner.next() : ""; + } + + public static byte[] serialize(T obj) + throws IOException { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + ObjectOutputStream oos = new ObjectOutputStream(baos); + oos.writeObject(obj); + oos.close(); + return baos.toByteArray(); + } + + public static T deserialize(byte[] bytes, Class cl) + throws IOException, ClassNotFoundException { + ByteArrayInputStream bais = new ByteArrayInputStream(bytes); + ObjectInputStream ois = new ObjectInputStream(bais); + Object object = ois.readObject(); + return cl.cast(object); + } + + /** + * Comes from Google Utils Test Case + */ + public static void expectNearNumber(double expected, double actual, double epsilon) { + assertTrue(String.format("Expected %f to be near %f", actual, expected), + Math.abs(expected - actual) <= epsilon); + } +} diff --git a/services-turf/src/test/java/com/mapbox/turf/TurfAssertionsTest.java b/services-turf/src/test/java/com/mapbox/turf/TurfAssertionsTest.java index 04de24fbc..47c25110f 100644 --- a/services-turf/src/test/java/com/mapbox/turf/TurfAssertionsTest.java +++ b/services-turf/src/test/java/com/mapbox/turf/TurfAssertionsTest.java @@ -2,7 +2,6 @@ import com.mapbox.geojson.Feature; import com.mapbox.geojson.Point; -import com.mapbox.core.TestUtils; import com.mapbox.geojson.FeatureCollection; import org.junit.Rule; diff --git a/services-turf/src/test/java/com/mapbox/turf/TurfClassificationTest.java b/services-turf/src/test/java/com/mapbox/turf/TurfClassificationTest.java index e88fdf293..b9fe3c3f1 100644 --- a/services-turf/src/test/java/com/mapbox/turf/TurfClassificationTest.java +++ b/services-turf/src/test/java/com/mapbox/turf/TurfClassificationTest.java @@ -2,7 +2,6 @@ import com.mapbox.geojson.Feature; import com.mapbox.geojson.Point; -import com.mapbox.core.TestUtils; import com.mapbox.geojson.FeatureCollection; import org.junit.Assert; diff --git a/services-turf/src/test/java/com/mapbox/turf/TurfConversionTest.java b/services-turf/src/test/java/com/mapbox/turf/TurfConversionTest.java index 78cc0d6eb..db1b4e7db 100644 --- a/services-turf/src/test/java/com/mapbox/turf/TurfConversionTest.java +++ b/services-turf/src/test/java/com/mapbox/turf/TurfConversionTest.java @@ -1,7 +1,5 @@ package com.mapbox.turf; -import com.mapbox.core.TestUtils; - import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; diff --git a/services-turf/src/test/java/com/mapbox/turf/TurfJoinsTest.java b/services-turf/src/test/java/com/mapbox/turf/TurfJoinsTest.java index d351c823f..fb33de8db 100644 --- a/services-turf/src/test/java/com/mapbox/turf/TurfJoinsTest.java +++ b/services-turf/src/test/java/com/mapbox/turf/TurfJoinsTest.java @@ -1,7 +1,6 @@ package com.mapbox.turf; import com.mapbox.geojson.Feature; -import com.mapbox.core.TestUtils; import com.mapbox.geojson.FeatureCollection; import com.mapbox.geojson.MultiPolygon; import com.mapbox.geojson.Point; diff --git a/services-turf/src/test/java/com/mapbox/turf/TurfMeasurementTest.java b/services-turf/src/test/java/com/mapbox/turf/TurfMeasurementTest.java index 1ca83e2f3..0b4d11031 100644 --- a/services-turf/src/test/java/com/mapbox/turf/TurfMeasurementTest.java +++ b/services-turf/src/test/java/com/mapbox/turf/TurfMeasurementTest.java @@ -1,6 +1,5 @@ package com.mapbox.turf; -import com.mapbox.core.TestUtils; import com.mapbox.geojson.Feature; import com.mapbox.geojson.FeatureCollection; import com.mapbox.geojson.Geometry; diff --git a/services-turf/src/test/java/com/mapbox/turf/TurfMetaTest.java b/services-turf/src/test/java/com/mapbox/turf/TurfMetaTest.java index 49f6faa94..7a67dbfca 100644 --- a/services-turf/src/test/java/com/mapbox/turf/TurfMetaTest.java +++ b/services-turf/src/test/java/com/mapbox/turf/TurfMetaTest.java @@ -4,7 +4,6 @@ import com.mapbox.geojson.LineString; import com.mapbox.geojson.Point; import com.mapbox.geojson.Polygon; -import com.mapbox.core.TestUtils; import com.mapbox.geojson.MultiPolygon; import org.junit.Rule; diff --git a/services-turf/src/test/java/com/mapbox/turf/TurfMiscTest.java b/services-turf/src/test/java/com/mapbox/turf/TurfMiscTest.java index a00ea5e15..913b6ee8a 100644 --- a/services-turf/src/test/java/com/mapbox/turf/TurfMiscTest.java +++ b/services-turf/src/test/java/com/mapbox/turf/TurfMiscTest.java @@ -1,6 +1,5 @@ package com.mapbox.turf; -import com.mapbox.core.TestUtils; import com.mapbox.geojson.Feature; import com.mapbox.geojson.LineString; import com.mapbox.geojson.Point; diff --git a/services-turf/src/test/java/com/mapbox/turf/TurfTransformationTest.java b/services-turf/src/test/java/com/mapbox/turf/TurfTransformationTest.java index 195b44197..ad41aec8a 100644 --- a/services-turf/src/test/java/com/mapbox/turf/TurfTransformationTest.java +++ b/services-turf/src/test/java/com/mapbox/turf/TurfTransformationTest.java @@ -1,7 +1,6 @@ package com.mapbox.turf; import com.mapbox.geojson.Feature; -import com.mapbox.core.TestUtils; import com.mapbox.geojson.FeatureCollection; import com.mapbox.geojson.Polygon; import com.mapbox.geojson.Point;