DATACMNS-867 - First draft.

This commit is contained in:
Oliver Gierke
2016-11-14 20:10:22 +01:00
parent 1b17271915
commit cc63e5b7a4
278 changed files with 4737 additions and 5714 deletions

View File

@@ -15,8 +15,7 @@
*/
package org.springframework.data.geo;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import org.junit.Test;
import org.springframework.util.SerializationUtils;
@@ -36,28 +35,28 @@ public class BoxUnitTests {
@Test // DATACMNS-437
public void equalsWorksCorrectly() {
assertThat(first.equals(second), is(true));
assertThat(second.equals(first), is(true));
assertThat(first.equals(third), is(false));
assertThat(first.equals(second)).isTrue();
assertThat(second.equals(first)).isTrue();
assertThat(first.equals(third)).isFalse();
}
@Test // DATACMNS-437
public void hashCodeWorksCorrectly() {
assertThat(first.hashCode(), is(second.hashCode()));
assertThat(first.hashCode(), is(not(third.hashCode())));
assertThat(first.hashCode()).isEqualTo(second.hashCode());
assertThat(first.hashCode()).isNotEqualTo(third.hashCode());
}
@Test // DATACMNS-437
public void testToString() {
assertThat(first.toString(), is("Box [Point [x=1.000000, y=1.000000], Point [x=2.000000, y=2.000000]]"));
assertThat(first.toString()).isEqualTo("Box [Point [x=1.000000, y=1.000000], Point [x=2.000000, y=2.000000]]");
}
@Test // DATACMNS-482
public void testSerialization() {
Box serialized = (Box) SerializationUtils.deserialize(SerializationUtils.serialize(first));
assertThat(serialized, is(first));
assertThat(serialized).isEqualTo(first);
}
}

View File

@@ -15,8 +15,7 @@
*/
package org.springframework.data.geo;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import org.junit.Test;
import org.springframework.util.SerializationUtils;
@@ -45,19 +44,19 @@ public class CircleUnitTests {
Circle left = new Circle(1, 1, 1);
Circle right = new Circle(1, 1, 1);
assertThat(left, is(right));
assertThat(right, is(left));
assertThat(left).isEqualTo(right);
assertThat(right).isEqualTo(left);
right = new Circle(new Point(1, 1), new Distance(1));
assertThat(left, is(right));
assertThat(right, is(left));
assertThat(left).isEqualTo(right);
assertThat(right).isEqualTo(left);
}
@Test // DATACMNS-437
public void testToString() {
assertThat(new Circle(1, 1, 1).toString(), is("Circle: [center=Point [x=1.000000, y=1.000000], radius=1.0]"));
assertThat(new Circle(1, 1, 1).toString()).isEqualTo("Circle: [center=Point [x=1.000000, y=1.000000], radius=1.0]");
}
@Test // DATACMNS-482
@@ -66,6 +65,6 @@ public class CircleUnitTests {
Circle circle = new Circle(1, 1, 1);
Circle serialized = (Circle) SerializationUtils.deserialize(SerializationUtils.serialize(circle));
assertThat(serialized, is(circle));
assertThat(serialized).isEqualTo(circle);
}
}

View File

@@ -15,10 +15,10 @@
*/
package org.springframework.data.geo;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.springframework.data.geo.Metrics.*;
import org.assertj.core.data.Offset;
import org.junit.Test;
import org.springframework.data.domain.Range;
import org.springframework.util.SerializationUtils;
@@ -31,15 +31,15 @@ import org.springframework.util.SerializationUtils;
*/
public class DistanceUnitTests {
private static final double EPS = 0.000000001;
private static final Offset<Double> EPS = Offset.offset(0.000000001);
private static final double TEN_MILES_NORMALIZED = 0.002523219294755161;
private static final double TEN_KM_NORMALIZED = 0.001567855942887398;
@Test // DATACMNS-437
public void defaultsMetricToNeutralOne() {
assertThat(new Distance(2.5).getMetric(), is((Metric) Metrics.NEUTRAL));
assertThat(new Distance(2.5, null).getMetric(), is((Metric) Metrics.NEUTRAL));
assertThat(new Distance(2.5).getMetric()).isEqualTo((Metric) Metrics.NEUTRAL);
assertThat(new Distance(2.5, null).getMetric()).isEqualTo((Metric) Metrics.NEUTRAL);
}
@Test // DATACMNS-437
@@ -48,7 +48,7 @@ public class DistanceUnitTests {
Distance left = new Distance(2.5, KILOMETERS);
Distance right = new Distance(2.5, KILOMETERS);
assertThat(left.add(right), is(new Distance(5.0, KILOMETERS)));
assertThat(left.add(right)).isEqualTo(new Distance(5.0, KILOMETERS));
}
@Test // DATACMNS-437
@@ -57,52 +57,53 @@ public class DistanceUnitTests {
Distance left = new Distance(2.5, KILOMETERS);
Distance right = new Distance(2.5, KILOMETERS);
assertThat(left.add(right, MILES), is(new Distance(3.106856281073925, MILES)));
assertThat(left.add(right, MILES)).isEqualTo(new Distance(3.106856281073925, MILES));
}
@Test // DATACMNS-474
public void distanceWithSameMetricShoudEqualAfterConversion() {
assertThat(new Distance(1).in(NEUTRAL), is(new Distance(1)));
assertThat(new Distance(TEN_KM_NORMALIZED).in(KILOMETERS), is(new Distance(10, KILOMETERS)));
assertThat(new Distance(TEN_MILES_NORMALIZED).in(MILES), is(new Distance(10, MILES)));
assertThat(new Distance(1).in(NEUTRAL)).isEqualTo(new Distance(1));
assertThat(new Distance(TEN_KM_NORMALIZED).in(KILOMETERS)).isEqualTo(new Distance(10, KILOMETERS));
assertThat(new Distance(TEN_MILES_NORMALIZED).in(MILES)).isEqualTo(new Distance(10, MILES));
}
@Test // DATACMNS-474
public void distanceWithDifferentMetricShoudEqualAfterConversion() {
assertThat(new Distance(10, MILES), is(new Distance(TEN_MILES_NORMALIZED).in(MILES)));
assertThat(new Distance(10, KILOMETERS), is(new Distance(TEN_KM_NORMALIZED).in(KILOMETERS)));
assertThat(new Distance(10, MILES)).isEqualTo(new Distance(TEN_MILES_NORMALIZED).in(MILES));
assertThat(new Distance(10, KILOMETERS)).isEqualTo(new Distance(TEN_KM_NORMALIZED).in(KILOMETERS));
}
@Test // DATACMNS-474
public void conversionShouldProduceCorrectNormalizedValue() {
assertThat(new Distance(TEN_KM_NORMALIZED, NEUTRAL).in(KILOMETERS).getNormalizedValue(),
closeTo(new Distance(10, KILOMETERS).getNormalizedValue(), EPS));
assertThat(new Distance(TEN_KM_NORMALIZED, NEUTRAL).in(KILOMETERS).getNormalizedValue())
.isCloseTo(new Distance(10, KILOMETERS).getNormalizedValue(), EPS);
assertThat(new Distance(TEN_KM_NORMALIZED).in(KILOMETERS).getNormalizedValue(),
closeTo(new Distance(10, KILOMETERS).getNormalizedValue(), EPS));
assertThat(new Distance(TEN_KM_NORMALIZED).in(KILOMETERS).getNormalizedValue())
.isCloseTo(new Distance(10, KILOMETERS).getNormalizedValue(), EPS);
assertThat(new Distance(TEN_MILES_NORMALIZED).in(MILES).getNormalizedValue(),
closeTo(new Distance(10, MILES).getNormalizedValue(), EPS));
assertThat(new Distance(TEN_MILES_NORMALIZED).in(MILES).getNormalizedValue())
.isCloseTo(new Distance(10, MILES).getNormalizedValue(), EPS);
assertThat(new Distance(TEN_MILES_NORMALIZED).in(MILES).getNormalizedValue(),
closeTo(new Distance(16.09344, KILOMETERS).getNormalizedValue(), EPS));
assertThat(new Distance(TEN_MILES_NORMALIZED).in(MILES).getNormalizedValue())
.isCloseTo(new Distance(16.09344, KILOMETERS).getNormalizedValue(), EPS);
assertThat(new Distance(TEN_MILES_NORMALIZED).in(KILOMETERS).getNormalizedValue(),
closeTo(new Distance(10, MILES).getNormalizedValue(), EPS));
assertThat(new Distance(TEN_MILES_NORMALIZED).in(KILOMETERS).getNormalizedValue())
.isCloseTo(new Distance(10, MILES).getNormalizedValue(), EPS);
assertThat(new Distance(10, KILOMETERS).in(MILES).getNormalizedValue(),
closeTo(new Distance(6.21371192, MILES).getNormalizedValue(), EPS));
assertThat(new Distance(10, KILOMETERS).in(MILES).getNormalizedValue())
.isCloseTo(new Distance(6.21371192, MILES).getNormalizedValue(), EPS);
}
@Test // DATACMNS-474
public void toStringAfterConversion() {
assertThat(new Distance(10, KILOMETERS).in(MILES).toString(), is(new Distance(6.21371256214785, MILES).toString()));
assertThat(new Distance(6.21371256214785, MILES).in(KILOMETERS).toString(),
is(new Distance(10, KILOMETERS).toString()));
assertThat(new Distance(10, KILOMETERS).in(MILES).toString())
.isEqualTo(new Distance(6.21371256214785, MILES).toString());
assertThat(new Distance(6.21371256214785, MILES).in(KILOMETERS).toString())
.isEqualTo(new Distance(10, KILOMETERS).toString());
}
@Test // DATACMNS-482
@@ -111,12 +112,12 @@ public class DistanceUnitTests {
Distance dist = new Distance(10, KILOMETERS);
Distance serialized = (Distance) SerializationUtils.deserialize(SerializationUtils.serialize(dist));
assertThat(serialized, is(dist));
assertThat(serialized).isEqualTo(dist);
}
@Test // DATACMNS-626
public void returnsMetricsAbbreviationAsUnit() {
assertThat(new Distance(10, KILOMETERS).getUnit(), is("km"));
assertThat(new Distance(10, KILOMETERS).getUnit()).isEqualTo("km");
}
@Test // DATACMNS-651
@@ -127,9 +128,9 @@ public class DistanceUnitTests {
Range<Distance> range = Distance.between(twoKilometers, tenKilometers);
assertThat(range, is(notNullValue()));
assertThat(range.getLowerBound(), is(twoKilometers));
assertThat(range.getUpperBound(), is(tenKilometers));
assertThat(range).isNotNull();
assertThat(range.getLowerBound()).isEqualTo(twoKilometers);
assertThat(range.getUpperBound()).isEqualTo(tenKilometers);
}
@Test // DATACMNS-651
@@ -140,9 +141,9 @@ public class DistanceUnitTests {
Range<Distance> range = Distance.between(2, KILOMETERS, 10, KILOMETERS);
assertThat(range, is(notNullValue()));
assertThat(range.getLowerBound(), is(twoKilometers));
assertThat(range.getUpperBound(), is(tenKilometers));
assertThat(range).isNotNull();
assertThat(range.getLowerBound()).isEqualTo(twoKilometers);
assertThat(range.getUpperBound()).isEqualTo(tenKilometers);
}
@Test // DATACMNS-651
@@ -152,11 +153,11 @@ public class DistanceUnitTests {
Distance tenKilometers = new Distance(10, KILOMETERS);
Distance tenKilometersInMiles = new Distance(6.21371256214785, MILES);
assertThat(tenKilometers.compareTo(tenKilometers), is(0));
assertThat(tenKilometers.compareTo(tenKilometersInMiles), is(0));
assertThat(tenKilometersInMiles.compareTo(tenKilometers), is(0));
assertThat(tenKilometers.compareTo(tenKilometers)).isEqualTo(0);
assertThat(tenKilometers.compareTo(tenKilometersInMiles)).isEqualTo(0);
assertThat(tenKilometersInMiles.compareTo(tenKilometers)).isEqualTo(0);
assertThat(twoKilometers.compareTo(tenKilometers), is(lessThan(0)));
assertThat(tenKilometers.compareTo(twoKilometers), is(greaterThan(0)));
assertThat(twoKilometers.compareTo(tenKilometers)).isLessThan(0);
assertThat(tenKilometers.compareTo(twoKilometers)).isGreaterThan(0);
}
}

View File

@@ -15,8 +15,7 @@
*/
package org.springframework.data.geo;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import org.junit.Before;
import org.junit.Test;
@@ -45,8 +44,8 @@ public class GeoModuleIntegrationTests {
String json = "{\"value\":10.0,\"metric\":\"KILOMETERS\"}";
Distance reference = new Distance(10.0, Metrics.KILOMETERS);
assertThat(mapper.readValue(json, Distance.class), is(reference));
assertThat(mapper.writeValueAsString(reference), is(json));
assertThat(mapper.readValue(json, Distance.class)).isEqualTo(reference);
assertThat(mapper.writeValueAsString(reference)).isEqualTo(json);
}
@Test // DATACMNS-475
@@ -55,8 +54,8 @@ public class GeoModuleIntegrationTests {
String json = "{\"x\":10.0,\"y\":20.0}";
Point reference = new Point(10.0, 20.0);
assertThat(mapper.readValue(json, Point.class), is(reference));
assertThat(mapper.writeValueAsString(reference), is(json));
assertThat(mapper.readValue(json, Point.class)).isEqualTo(reference);
assertThat(mapper.writeValueAsString(reference)).isEqualTo(json);
}
@Test // DATACMNS-475
@@ -65,8 +64,8 @@ public class GeoModuleIntegrationTests {
String json = "{\"center\":{\"x\":10.0,\"y\":20.0},\"radius\":{\"value\":10.0,\"metric\":\"KILOMETERS\"}}";
Circle reference = new Circle(new Point(10.0, 20.0), new Distance(10, Metrics.KILOMETERS));
assertThat(mapper.readValue(json, Circle.class), is(reference));
assertThat(mapper.writeValueAsString(reference), is(json));
assertThat(mapper.readValue(json, Circle.class)).isEqualTo(reference);
assertThat(mapper.writeValueAsString(reference)).isEqualTo(json);
}
@Test // DATACMNS-475
@@ -75,8 +74,8 @@ public class GeoModuleIntegrationTests {
String json = "{\"first\":{\"x\":1.0,\"y\":2.0},\"second\":{\"x\":2.0,\"y\":3.0}}";
Box reference = new Box(new Point(1, 2), new Point(2, 3));
assertThat(mapper.readValue(json, Box.class), is(reference));
assertThat(mapper.writeValueAsString(reference), is(json));
assertThat(mapper.readValue(json, Box.class)).isEqualTo(reference);
assertThat(mapper.writeValueAsString(reference)).isEqualTo(json);
}
@Test // DATACMNS-475
@@ -85,7 +84,7 @@ public class GeoModuleIntegrationTests {
String json = "{\"points\":[{\"x\":1.0,\"y\":2.0},{\"x\":2.0,\"y\":3.0},{\"x\":3.0,\"y\":4.0}]}";
Polygon reference = new Polygon(new Point(1, 2), new Point(2, 3), new Point(3, 4));
assertThat(mapper.readValue(json, Polygon.class), is(reference));
assertThat(mapper.writeValueAsString(reference), is(json));
assertThat(mapper.readValue(json, Polygon.class)).isEqualTo(reference);
assertThat(mapper.writeValueAsString(reference)).isEqualTo(json);
}
}

View File

@@ -15,8 +15,7 @@
*/
package org.springframework.data.geo;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import org.junit.Test;
import org.springframework.util.SerializationUtils;
@@ -37,18 +36,18 @@ public class GeoResultUnitTests {
@Test // DATACMNS-437
public void considersSameInstanceEqual() {
assertThat(first.equals(first), is(true));
assertThat(first.equals(first)).isTrue();
}
@Test // DATACMNS-437
public void considersSameValuesAsEqual() {
assertThat(first.equals(second), is(true));
assertThat(second.equals(first), is(true));
assertThat(first.equals(third), is(false));
assertThat(third.equals(first), is(false));
assertThat(first.equals(fourth), is(false));
assertThat(fourth.equals(first), is(false));
assertThat(first.equals(second)).isTrue();
assertThat(second.equals(first)).isTrue();
assertThat(first.equals(third)).isFalse();
assertThat(third.equals(first)).isFalse();
assertThat(first.equals(fourth)).isFalse();
assertThat(fourth.equals(first)).isFalse();
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@@ -64,6 +63,6 @@ public class GeoResultUnitTests {
@SuppressWarnings("unchecked")
GeoResult<String> serialized = (GeoResult<String>) SerializationUtils.deserialize(SerializationUtils.serialize(result));
assertThat(serialized, is(result));
assertThat(serialized).isEqualTo(result);
}
}

View File

@@ -15,8 +15,7 @@
*/
package org.springframework.data.geo;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import java.util.Arrays;
@@ -35,23 +34,22 @@ public class GeoResultsUnitTests {
@SuppressWarnings("unchecked")
public void calculatesAverageForGivenGeoResults() {
GeoResult<Object> first = new GeoResult<Object>(new Object(), new Distance(2));
GeoResult<Object> second = new GeoResult<Object>(new Object(), new Distance(5));
GeoResults<Object> geoResults = new GeoResults<Object>(Arrays.asList(first, second));
GeoResult<Object> first = new GeoResult<>(new Object(), new Distance(2));
GeoResult<Object> second = new GeoResult<>(new Object(), new Distance(5));
GeoResults<Object> geoResults = new GeoResults<>(Arrays.asList(first, second));
assertThat(geoResults.getAverageDistance(), is(new Distance(3.5)));
assertThat(geoResults.getAverageDistance()).isEqualTo(new Distance(3.5));
}
@Test // DATACMNS-482
public void testSerialization() {
GeoResult<String> result = new GeoResult<String>("test", new Distance(2));
@SuppressWarnings("unchecked")
GeoResults<String> geoResults = new GeoResults<String>(Arrays.asList(result));
GeoResult<String> result = new GeoResult<>("test", new Distance(2));
GeoResults<String> geoResults = new GeoResults<>(Arrays.asList(result));
@SuppressWarnings("unchecked")
GeoResults<String> serialized = (GeoResults<String>) SerializationUtils.deserialize(SerializationUtils
.serialize(geoResults));
assertThat(serialized, is(geoResults));
GeoResults<String> serialized = (GeoResults<String>) SerializationUtils
.deserialize(SerializationUtils.serialize(geoResults));
assertThat(serialized).isEqualTo(geoResults);
}
}

View File

@@ -15,8 +15,7 @@
*/
package org.springframework.data.geo;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import org.junit.Test;
import org.springframework.util.SerializationUtils;
@@ -37,14 +36,14 @@ public class PointUnitTests {
@Test // DATACMNS-437
public void equalsIsImplementedCorrectly() {
assertThat(new Point(1.5, 1.5), is(equalTo(new Point(1.5, 1.5))));
assertThat(new Point(1.5, 1.5), is(not(equalTo(new Point(2.0, 2.0)))));
assertThat(new Point(2.0, 2.0), is(not(equalTo(new Point(1.5, 1.5)))));
assertThat(new Point(1.5, 1.5)).isEqualTo(new Point(1.5, 1.5));
assertThat(new Point(1.5, 1.5)).isNotEqualTo(new Point(2.0, 2.0));
assertThat(new Point(2.0, 2.0)).isNotEqualTo(new Point(1.5, 1.5));
}
@Test // DATACMNS-437
public void invokingToStringWorksCorrectly() {
assertThat(new Point(1.5, 1.5).toString(), is("Point [x=1.500000, y=1.500000]"));
assertThat(new Point(1.5, 1.5).toString()).isEqualTo("Point [x=1.500000, y=1.500000]");
}
@Test // DATACMNS-482
@@ -53,6 +52,6 @@ public class PointUnitTests {
Point point = new Point(1.5, 1.5);
Point serialized = (Point) SerializationUtils.deserialize(SerializationUtils.serialize(point));
assertThat(serialized, is(point));
assertThat(serialized).isEqualTo(point);
}
}

View File

@@ -15,8 +15,7 @@
*/
package org.springframework.data.geo;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import org.junit.Test;
import org.springframework.util.SerializationUtils;
@@ -43,7 +42,7 @@ public class PolygonUnitTests {
Polygon polygon = new Polygon(third, second, first);
assertThat(polygon, is(notNullValue()));
assertThat(polygon).isNotNull();
}
@Test // DATACMNS-437
@@ -52,15 +51,15 @@ public class PolygonUnitTests {
Polygon left = new Polygon(third, second, first);
Polygon right = new Polygon(third, second, first);
assertThat(left, is(right));
assertThat(right, is(left));
assertThat(left).isEqualTo(right);
assertThat(right).isEqualTo(left);
}
@Test // DATACMNS-437
public void testToString() {
assertThat(new Polygon(third, second, first).toString(),
is("Polygon: [Point [x=3.000000, y=3.000000],Point [x=2.000000, y=2.000000],Point [x=1.000000, y=1.000000]]"));
assertThat(new Polygon(third, second, first).toString()).isEqualTo(
"Polygon: [Point [x=3.000000, y=3.000000],Point [x=2.000000, y=2.000000],Point [x=1.000000, y=1.000000]]");
}
@Test // DATACMNS-482
@@ -69,6 +68,6 @@ public class PolygonUnitTests {
Polygon polygon = new Polygon(third, second, first);
Polygon serialized = (Polygon) SerializationUtils.deserialize(SerializationUtils.serialize(polygon));
assertThat(serialized, is(polygon));
assertThat(serialized).isEqualTo(polygon);
}
}

View File

@@ -15,8 +15,7 @@
*/
package org.springframework.data.geo.format;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.springframework.data.geo.format.DistanceFormatter.*;
import java.text.ParseException;
@@ -62,7 +61,7 @@ public class DistanceFormatterUnitTests {
@Test // DATAREST-279, DATACMNS-626
public void printsDistance() {
assertThat(INSTANCE.print(REFERENCE, Locale.US), is("10.8km"));
assertThat(INSTANCE.print(REFERENCE, Locale.US)).isEqualTo("10.8km");
}
}
@@ -80,12 +79,12 @@ public class DistanceFormatterUnitTests {
@Test // DATAREST-279, DATACMNS-626
public void parsesDistanceFromString() {
assertThat(INSTANCE.convert(source), is(REFERENCE));
assertThat(INSTANCE.convert(source)).isEqualTo(REFERENCE);
}
@Test
public void parsesDistances() throws ParseException {
assertThat(INSTANCE.parse(source, Locale.US), is(REFERENCE));
assertThat(INSTANCE.parse(source, Locale.US)).isEqualTo(REFERENCE);
}
}
}

View File

@@ -15,8 +15,7 @@
*/
package org.springframework.data.geo.format;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import static org.springframework.data.geo.format.PointFormatter.*;
import java.text.ParseException;
@@ -86,12 +85,12 @@ public class PointFormatterUnitTests {
@Test // DATAREST-279, DATACMNS-626
public void convertsPointFromString() {
assertThat(INSTANCE.convert(source), is(REFERENCE));
assertThat(INSTANCE.convert(source)).isEqualTo(REFERENCE);
}
@Test // DATAREST-279, DATACMNS-626
public void parsesPoint() throws ParseException {
assertThat(INSTANCE.parse(source, Locale.US), is(REFERENCE));
assertThat(INSTANCE.parse(source, Locale.US)).isEqualTo(REFERENCE);
}
}
}