This is an automated email from the ASF dual-hosted git repository.
enorman pushed a commit to branch master
in repository
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-jcr-mock.git
The following commit(s) were added to refs/heads/master by this push:
new 11453f2 SLING-11863 getAncestor interprets the depth argument
incorrectly (#19)
11453f2 is described below
commit 11453f2469039de7849dce59e51014153001d077
Author: Eric Norman <[email protected]>
AuthorDate: Wed May 10 11:04:28 2023 -0700
SLING-11863 getAncestor interprets the depth argument incorrectly (#19)
---
.../org/apache/sling/testing/mock/jcr/AbstractItem.java | 2 +-
.../apache/sling/testing/mock/jcr/AbstractItemTest.java | 16 +++++++++-------
2 files changed, 10 insertions(+), 8 deletions(-)
diff --git a/src/main/java/org/apache/sling/testing/mock/jcr/AbstractItem.java
b/src/main/java/org/apache/sling/testing/mock/jcr/AbstractItem.java
index 898c541..09634ca 100644
--- a/src/main/java/org/apache/sling/testing/mock/jcr/AbstractItem.java
+++ b/src/main/java/org/apache/sling/testing/mock/jcr/AbstractItem.java
@@ -76,7 +76,7 @@ abstract class AbstractItem implements Item {
if (depth < 0 || depth > getDepth()) {
throw new ItemNotFoundException();
}
- return this.session.getItem(ResourceUtil.getParent(getPath(), depth));
+ return this.session.getItem(ResourceUtil.getParent(getPath(),
getDepth() - depth));
}
protected String makeAbsolutePath(final String relativePath) throws
RepositoryException {
diff --git
a/src/test/java/org/apache/sling/testing/mock/jcr/AbstractItemTest.java
b/src/test/java/org/apache/sling/testing/mock/jcr/AbstractItemTest.java
index 4e0e174..205d77d 100644
--- a/src/test/java/org/apache/sling/testing/mock/jcr/AbstractItemTest.java
+++ b/src/test/java/org/apache/sling/testing/mock/jcr/AbstractItemTest.java
@@ -20,7 +20,7 @@ package org.apache.sling.testing.mock.jcr;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import javax.jcr.ItemNotFoundException;
@@ -64,19 +64,21 @@ public abstract class AbstractItemTest {
@Test
public void testGetAncestor() throws RepositoryException {
- assertTrue(this.node11.isSame(this.node11.getAncestor(0)));
+ assertTrue(this.rootNode.isSame(this.node11.getAncestor(0)));
assertTrue(this.node1.isSame(this.node11.getAncestor(1)));
- assertTrue(this.rootNode.isSame(this.node11.getAncestor(2)));
+ assertTrue(this.node11.isSame(this.node11.getAncestor(2)));
}
- @Test(expected = ItemNotFoundException.class)
+ @Test
public void testGetAncestorNegative() throws RepositoryException {
- assertSame(this.node11, this.node11.getAncestor(-1));
+ assertThrows(ItemNotFoundException.class,
+ () -> this.node11.getAncestor(-1));
}
- @Test(expected = ItemNotFoundException.class)
+ @Test
public void testGetAncestorTooDeep() throws RepositoryException {
- this.node11.getAncestor(3);
+ assertThrows(ItemNotFoundException.class,
+ () -> this.node11.getAncestor(3));
}
@Test