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:
@@ -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);
|
||||
|
||||
@@ -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" })
|
||||
|
||||
Reference in New Issue
Block a user