DATAMONGO-1782 - Polishing.

toCyclePath now returns an empty String when Path does not cycle.
Also split and add tests.

Original Pull Request: #500
This commit is contained in:
Christoph Strobl
2017-09-19 09:33:10 +02:00
parent 72a0a5623a
commit ae8df6b705
2 changed files with 32 additions and 4 deletions

View File

@@ -622,6 +622,10 @@ public class MongoPersistentEntityIndexResolver implements IndexResolver {
*/
String toCyclePath() {
if(!cycle) {
return "";
}
for (int i = 0; i < this.elements.size(); i++) {
int index = indexOf(this.elements, this.elements.get(i), i + 1);

View File

@@ -52,10 +52,34 @@ public class PathUnitTests {
MongoPersistentProperty foo = createPersistentPropertyMock(entityMock, "foo");
MongoPersistentProperty bar = createPersistentPropertyMock(entityMock, "bar");
assertThat(Path.of(foo).append(bar).isCycle(), is(false));
assertThat(Path.of(foo).append(bar).append(bar).isCycle(), is(true));
assertThat(Path.of(foo).append(bar).append(bar).toCyclePath(), is(equalTo("bar -> bar")));
assertThat(Path.of(foo).append(bar).append(bar).toString(), is(equalTo("foo -> bar -> bar")));
Path path = Path.of(foo).append(bar).append(bar);
assertThat(path.isCycle(), is(true));
assertThat(path.toCyclePath(), is(equalTo("bar -> bar")));
assertThat(path.toString(), is(equalTo("foo -> bar -> bar")));
}
@Test // DATAMONGO-1782
public void isCycleShouldReturnFalseWhenNoCyclePresent() {
MongoPersistentProperty foo = createPersistentPropertyMock(entityMock, "foo");
MongoPersistentProperty bar = createPersistentPropertyMock(entityMock, "bar");
Path path = Path.of(foo).append(bar);
assertThat(path.isCycle(), is(false));
assertThat(path.toCyclePath(), is(equalTo("")));
assertThat(path.toString(), is(equalTo("foo -> bar")));
}
@Test // DATAMONGO-1782
public void isCycleShouldReturnFalseCycleForNonEqualProperties() {
MongoPersistentProperty foo = createPersistentPropertyMock(entityMock, "foo");
MongoPersistentProperty bar = createPersistentPropertyMock(entityMock, "bar");
MongoPersistentProperty bar2 = createPersistentPropertyMock(mock(MongoPersistentEntity.class), "bar");
assertThat(Path.of(foo).append(bar).append(bar2).isCycle(), is(false));
}
@SuppressWarnings({ "rawtypes", "unchecked" })