-
Notifications
You must be signed in to change notification settings - Fork 986
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix bug in GeoCoordinates.toString and extend tests #86
- Loading branch information
Showing
2 changed files
with
149 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
package com.lambdaworks.redis; | ||
|
||
import static org.assertj.core.api.Assertions.*; | ||
|
||
import java.util.Map; | ||
|
||
import org.junit.Test; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">Mark Paluch</a> | ||
* @since 06.07.15 14:18 | ||
*/ | ||
public class GeoModelTest { | ||
|
||
@Test | ||
public void geoWithin() throws Exception { | ||
|
||
GeoWithin<String> sut = new GeoWithin<String>("me", 1.0, 1234L, new GeoCoordinates(1, 2)); | ||
GeoWithin<String> equalsToSut = new GeoWithin<String>("me", 1.0, 1234L, new GeoCoordinates(1, 2)); | ||
|
||
Map<GeoWithin<String>, String> map = ImmutableMap.of(sut, "value"); | ||
|
||
assertThat(map.get(equalsToSut)).isEqualTo("value"); | ||
assertThat(sut).isEqualTo(equalsToSut); | ||
assertThat(sut.hashCode()).isEqualTo(equalsToSut.hashCode()); | ||
assertThat(sut.toString()).isEqualTo(equalsToSut.toString()); | ||
|
||
} | ||
|
||
@Test | ||
public void geoWithinSlightlyDifferent() throws Exception { | ||
|
||
GeoWithin<String> sut = new GeoWithin<String>("me", 1.0, 1234L, new GeoCoordinates(1, 2)); | ||
GeoWithin<String> slightlyDifferent = new GeoWithin<String>("me", 1.0, 1234L, new GeoCoordinates(1.1, 2)); | ||
|
||
Map<GeoWithin<String>, String> map = ImmutableMap.of(sut, "value"); | ||
|
||
assertThat(map.get(slightlyDifferent)).isNull(); | ||
assertThat(sut).isNotEqualTo(slightlyDifferent); | ||
assertThat(sut.hashCode()).isNotEqualTo(slightlyDifferent.hashCode()); | ||
assertThat(sut.toString()).isNotEqualTo(slightlyDifferent.toString()); | ||
|
||
slightlyDifferent = new GeoWithin<String>("me1", 1.0, 1234L, new GeoCoordinates(1, 2)); | ||
assertThat(sut).isNotEqualTo(slightlyDifferent); | ||
} | ||
|
||
@Test | ||
public void geoWithinEmpty() throws Exception { | ||
|
||
GeoWithin<String> sut = new GeoWithin<String>(null, null, null, null); | ||
GeoWithin<String> equalsToSut = new GeoWithin<String>(null, null, null, null); | ||
|
||
assertThat(sut).isEqualTo(equalsToSut); | ||
assertThat(sut.hashCode()).isEqualTo(equalsToSut.hashCode()); | ||
} | ||
|
||
@Test | ||
public void geoCoordinates() throws Exception { | ||
|
||
GeoCoordinates sut = new GeoCoordinates(1, 2); | ||
GeoCoordinates equalsToSut = new GeoCoordinates(1, 2); | ||
|
||
Map<GeoCoordinates, String> map = ImmutableMap.of(sut, "value"); | ||
|
||
assertThat(map.get(equalsToSut)).isEqualTo("value"); | ||
assertThat(sut).isEqualTo(equalsToSut); | ||
assertThat(sut.hashCode()).isEqualTo(equalsToSut.hashCode()); | ||
assertThat(sut.toString()).isEqualTo(equalsToSut.toString()); | ||
|
||
} | ||
|
||
@Test | ||
public void geoCoordinatesSlightlyDifferent() throws Exception { | ||
|
||
GeoCoordinates sut = new GeoCoordinates(1, 2); | ||
GeoCoordinates slightlyDifferent = new GeoCoordinates(1.1, 2); | ||
|
||
Map<GeoCoordinates, String> map = ImmutableMap.of(sut, "value"); | ||
|
||
assertThat(map.get(slightlyDifferent)).isNull(); | ||
assertThat(sut).isNotEqualTo(slightlyDifferent); | ||
assertThat(sut.hashCode()).isNotEqualTo(slightlyDifferent.hashCode()); | ||
assertThat(sut.toString()).isNotEqualTo(slightlyDifferent.toString()); | ||
|
||
} | ||
|
||
@Test | ||
public void geoCoordinatesEmpty() throws Exception { | ||
|
||
GeoCoordinates sut = new GeoCoordinates(null, null); | ||
GeoCoordinates equalsToSut = new GeoCoordinates(null, null); | ||
|
||
assertThat(sut).isEqualTo(equalsToSut); | ||
assertThat(sut.hashCode()).isEqualTo(equalsToSut.hashCode()); | ||
} | ||
|
||
@Test | ||
public void geoEncoded() throws Exception { | ||
|
||
GeoEncoded sut = new GeoEncoded(1234, new GeoCoordinates(null, 1), new GeoCoordinates(1, null), | ||
new GeoCoordinates(1, 2)); | ||
GeoEncoded equalsToSut = new GeoEncoded(1234, new GeoCoordinates(null, 1), new GeoCoordinates(1, null), | ||
new GeoCoordinates(1, 2)); | ||
|
||
Map<GeoEncoded, String> map = ImmutableMap.of(sut, "value"); | ||
|
||
assertThat(map.get(sut)).isEqualTo("value"); | ||
assertThat(sut).isEqualTo(equalsToSut); | ||
assertThat(sut.hashCode()).isEqualTo(equalsToSut.hashCode()); | ||
assertThat(sut.toString()).isEqualTo(equalsToSut.toString()); | ||
|
||
} | ||
|
||
@Test | ||
public void geoEncodedSlightlyDifferent() throws Exception { | ||
|
||
GeoEncoded sut = new GeoEncoded(1234, new GeoCoordinates(null, 1), new GeoCoordinates(1, 555.5), new GeoCoordinates(1, | ||
2)); | ||
GeoEncoded slightlyDifferent = new GeoEncoded(1234, new GeoCoordinates(null, 1), new GeoCoordinates(1, null), | ||
new GeoCoordinates(1, 2)); | ||
|
||
Map<GeoEncoded, String> map = ImmutableMap.of(sut, "value"); | ||
|
||
assertThat(map.get(slightlyDifferent)).isNull(); | ||
assertThat(sut).isNotEqualTo(slightlyDifferent); | ||
assertThat(sut).isNotEqualTo( | ||
slightlyDifferent = new GeoEncoded(0, new GeoCoordinates(null, 1), new GeoCoordinates(1, null), | ||
new GeoCoordinates(1, 2))); | ||
assertThat(sut.hashCode()).isNotEqualTo(slightlyDifferent.hashCode()); | ||
assertThat(sut.toString()).isNotEqualTo(slightlyDifferent.toString()); | ||
|
||
} | ||
|
||
@Test | ||
public void geoEncodedEmpty() throws Exception { | ||
|
||
GeoEncoded sut = new GeoEncoded(0, null, null, null); | ||
GeoEncoded equalsToSut = new GeoEncoded(0, null, null, null); | ||
|
||
assertThat(sut).isEqualTo(equalsToSut); | ||
assertThat(sut.hashCode()).isEqualTo(equalsToSut.hashCode()); | ||
} | ||
} |