Author: rhauch
Date: 2008-09-10 14:05:54 -0400 (Wed, 10 Sep 2008)
New Revision: 514
Modified:
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPathSegment.java
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicPathSegmentTest.java
trunk/extensions/dna-connector-inmemory/src/test/java/org/jboss/dna/connector/inmemory/InMemoryRepositoryTest.java
Log:
DNA-220 - Path segment without an index is not considered equal to a segment with an index
of 1
http://jira.jboss.com/jira/browse/DNA-220
Changed the behavior of BasicPathSegment.equals(...) so that a segment without an index is
equivalent to another segment with the same name but with an index of 1. Also corrected a
test case of the InMemory connector.
Modified: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPathSegment.java
===================================================================
---
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPathSegment.java 2008-09-10
15:19:33 UTC (rev 513)
+++
trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/impl/BasicPathSegment.java 2008-09-10
18:05:54 UTC (rev 514)
@@ -125,7 +125,7 @@
if (obj instanceof Path.Segment) {
Path.Segment that = (Path.Segment)obj;
if (!this.getName().equals(that.getName())) return false;
- return this.getIndex() == that.getIndex();
+ return Math.abs(getIndex()) == Math.abs(that.getIndex());
}
return false;
}
Modified:
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicPathSegmentTest.java
===================================================================
---
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicPathSegmentTest.java 2008-09-10
15:19:33 UTC (rev 513)
+++
trunk/dna-spi/src/test/java/org/jboss/dna/spi/graph/impl/BasicPathSegmentTest.java 2008-09-10
18:05:54 UTC (rev 514)
@@ -22,6 +22,7 @@
package org.jboss.dna.spi.graph.impl;
import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNot.not;
import static org.junit.Assert.assertThat;
import org.jboss.dna.common.text.TextEncoder;
import org.jboss.dna.spi.DnaLexicon;
@@ -141,4 +142,20 @@
assertThat(segment.equals(Path.PARENT_SEGMENT), is(true));
}
+ @Test
+ public void
shouldConsiderSegmentWithSameNameSiblingIndexOfOneToBeEqualToSegmentWithSameNameButNoIndex()
{
+ segment = new BasicPathSegment(validName, Path.NO_INDEX);
+ Path.Segment segment2 = new BasicPathSegment(validName, 1);
+ assertThat(segment, is(segment2));
+ }
+
+ @Test
+ public void
shouldConsiderSegmentWithSameNameSiblingIndexOfTwoOrMoreToNotBeEqualToSegmentWithSameNameButNoIndex()
{
+ segment = new BasicPathSegment(validName, Path.NO_INDEX);
+ Path.Segment segment2 = new BasicPathSegment(validName, 2);
+ assertThat(segment, is(not(segment2)));
+ segment2 = new BasicPathSegment(validName, 3);
+ assertThat(segment, is(not(segment2)));
+ }
+
}
Modified:
trunk/extensions/dna-connector-inmemory/src/test/java/org/jboss/dna/connector/inmemory/InMemoryRepositoryTest.java
===================================================================
---
trunk/extensions/dna-connector-inmemory/src/test/java/org/jboss/dna/connector/inmemory/InMemoryRepositoryTest.java 2008-09-10
15:19:33 UTC (rev 513)
+++
trunk/extensions/dna-connector-inmemory/src/test/java/org/jboss/dna/connector/inmemory/InMemoryRepositoryTest.java 2008-09-10
18:05:54 UTC (rev 514)
@@ -187,7 +187,13 @@
/*Node node_c =*/repository.createNode(context, node_b,
nameFactory.create("c"), null);
assertThat(repository.getNodesByUuid().size(), is(4));
- assertThat(repository.getNode(pathFactory.create("/a[1]")),
is(nullValue()));
+ assertThat(repository.getNode(pathFactory.create("/a")), is(node_a));
+ assertThat(repository.getNode(pathFactory.create("/a/b")),
is(node_b));
+ assertThat(repository.getNode(pathFactory.create("/a[1]")),
is(node_a));
+ assertThat(repository.getNode(pathFactory.create("/a/b[1]")),
is(node_b));
+ assertThat(repository.getNode(pathFactory.create("/a[1]/b[1]")),
is(node_b));
+ assertThat(repository.getNode(pathFactory.create("/a[2]")),
is(nullValue()));
+ assertThat(repository.getNode(pathFactory.create("/b[2]")),
is(nullValue()));
assertThat(repository.getNode(pathFactory.create("/d")),
is(nullValue()));
}