Fixed GeoResultsUnitTests.

This commit is contained in:
Oliver Gierke
2011-08-22 17:37:37 +02:00
parent ce59d893ba
commit 7610246a1d
3 changed files with 21 additions and 1 deletions

View File

@@ -136,7 +136,7 @@ public class Distance {
StringBuilder builder = new StringBuilder();
builder.append(value);
if (metric != null) {
if (metric != Metrics.NEUTRAL) {
builder.append(" ").append(metric.toString());
}

View File

@@ -61,6 +61,8 @@ public class GeoResults<T> implements Iterable<GeoResult<T>> {
}
/**
* Returns the average distance of all {@link GeoResult}s in this list.
*
* @return the averageDistance
*/
public Distance getAverageDistance() {

View File

@@ -15,10 +15,28 @@
*/
package org.springframework.data.mongodb.core.geo;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import java.util.Arrays;
import org.junit.Test;
/**
* Unit tests for {@link GeoResults}.
*
* @author Oliver Gierke
*/
public class GeoResultsUnitTests {
@Test
@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));
assertThat(geoResults.getAverageDistance(), is(new Distance(3.5)));
}
}