public boolean satisfiesConstraints( Object[] tuple ) { Location location = (Location)tuple[locationIndex]; assert location.hasPath(); return location.getPath().isDecendantOf(ancestorPath); } };
@Test( expected = IllegalArgumentException.class ) public void shouldFailForDecendantOfNullPath() { path.isDecendantOf(null); }
@Test( expected = IllegalArgumentException.class ) public void shouldFailForDecendantOfNullPath() { path.isDecendantOf(null); }
@Test public void shouldNotConsiderRootNodeToBeDecendantOfAnyNode() { Path other = mock(Path.class); assertThat(root.isDecendantOf(other), is(false)); assertThat(root.isDecendantOf(root), is(false)); }
@Test public void shouldConsiderChildPathToBeDecendantOfParent() { assertThat(path.isDecendantOf(parent), is(true)); }
@Test public void shouldNotConsiderRootToBeDecendantOfItself() { assertThat(ROOT.isDecendantOf(ROOT), is(false)); }
@Test public void shouldNotConsiderRootToBeDecendantOfAnyNode() { Path path1 = pathFactory.create("/a/y/z"); Path path2 = pathFactory.create("/a/b/c"); Path path3 = pathFactory.create("/x/b/c"); Path common = pathFactory.create("/a"); assertThat(ROOT.isDecendantOf(path1), is(false)); assertThat(ROOT.isDecendantOf(path2), is(false)); assertThat(ROOT.isDecendantOf(path3), is(false)); assertThat(ROOT.isDecendantOf(common), is(false)); }
@Test public void shouldConsiderParentNotBeDecendantOfChildPath() { assertThat(parent.isDecendantOf(path), is(false)); }
@Test public void shouldNotConsiderNodeToBeDecendantOfItself() { assertThat(path.isDecendantOf(path), is(false)); }
@Test public void shouldNotConsiderNodeToBeDecendantOfItself() { Path path1 = pathFactory.create("/a/y/z"); Path path2 = pathFactory.create("/a/b/c"); Path path3 = pathFactory.create("/x/b/c"); assertThat(path1.isDecendantOf(path1), is(false)); assertThat(path2.isDecendantOf(path2), is(false)); assertThat(path3.isDecendantOf(path3), is(false)); assertThat(ROOT.isDecendantOf(ROOT), is(false)); }
@Test public void shouldNotConsiderRootToBeDecendantOfAnyNode() { Path path1 = pathFactory.create("/a/y/z"); Path path2 = pathFactory.create("/a/b/c"); Path path3 = pathFactory.create("/x/b/c"); Path common = pathFactory.create("/a"); assertThat(ROOT.isDecendantOf(path1), is(false)); assertThat(ROOT.isDecendantOf(path2), is(false)); assertThat(ROOT.isDecendantOf(path3), is(false)); assertThat(ROOT.isDecendantOf(common), is(false)); }
@Test public void shouldConsiderPathDecendantOfOtherParentPath() { assertThat(path.isDecendantOf(parent), is(true)); }
@Test public void shouldConsiderPathDecendantOfOtherPathIfParentIsAtOrBelowOtherPath() { parent = mock(Path.class); path = new ChildPath(parent, segment("d")); Path other = mock(Path.class); when(parent.isAtOrBelow(other)).thenReturn(true); assertThat(path.isDecendantOf(other), is(true)); verify(parent).isAtOrBelow(other); when(parent.isAtOrBelow(other)).thenReturn(false); assertThat(path.isDecendantOf(other), is(false)); verify(parent, times(2)).isAtOrBelow(other); }
@Override @Test public void shouldNotConsiderNodeToBeDecendantOfItself() { super.shouldNotConsiderNodeToBeDecendantOfItself(); Path path1 = pathFactory.create("/a/y/z"); Path path2 = pathFactory.create("/a/b/c"); Path path3 = pathFactory.create("/x/b/c"); assertThat(path1.isDecendantOf(path1), is(false)); assertThat(path2.isDecendantOf(path2), is(false)); assertThat(path3.isDecendantOf(path3), is(false)); assertThat(ROOT.isDecendantOf(ROOT), is(false)); }
@Test public void shouldConsiderNodeToBeDecendantOfEveryAncestorNode() { Path path1 = pathFactory.create("/a/y/z"); Path path2 = pathFactory.create("/a/b/c"); Path path3 = pathFactory.create("/x/b/c"); Path path4 = pathFactory.create("/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z"); Path common = pathFactory.create("/a"); assertThat(path1.isDecendantOf(common), is(true)); assertThat(path2.isDecendantOf(common), is(true)); assertThat(path3.isDecendantOf(common), is(false)); assertThat(path1.getParent().isAncestorOf(path1), is(true)); for (int i = 1; i < path1.size(); ++i) { assertThat(path1.isDecendantOf(path1.getAncestor(i)), is(true)); } for (int i = 1; i < path2.size(); ++i) { assertThat(path2.isDecendantOf(path2.getAncestor(i)), is(true)); } for (int i = 1; i < path3.size(); ++i) { assertThat(path3.isDecendantOf(path3.getAncestor(i)), is(true)); } for (int i = 1; i < path4.size(); ++i) { assertThat(path4.isDecendantOf(path4.getAncestor(i)), is(true)); } }
@Test public void shouldConsiderNodeToBeDecendantOfEveryAncestorNode() { Path path1 = pathFactory.create("/a/y/z"); Path path2 = pathFactory.create("/a/b/c"); Path path3 = pathFactory.create("/x/b/c"); Path path4 = pathFactory.create("/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z"); Path common = pathFactory.create("/a"); assertThat(path1.isDecendantOf(common), is(true)); assertThat(path2.isDecendantOf(common), is(true)); assertThat(path3.isDecendantOf(common), is(false)); assertThat(path1.getParent().isAncestorOf(path1), is(true)); for (int i = 1; i < path1.size(); ++i) { assertThat(path1.isDecendantOf(path1.getAncestor(i)), is(true)); } for (int i = 1; i < path2.size(); ++i) { assertThat(path2.isDecendantOf(path2.getAncestor(i)), is(true)); } for (int i = 1; i < path3.size(); ++i) { assertThat(path3.isDecendantOf(path3.getAncestor(i)), is(true)); } for (int i = 1; i < path4.size(); ++i) { assertThat(path4.isDecendantOf(path4.getAncestor(i)), is(true)); } }
if (path.isDecendantOf(offset)) { Path pathBelowOffset = path.relativeTo(offset); PathFactory pathFactory = context.getValueFactories().getPathFactory();
else if (highest.getPath().isDecendantOf(actual.getPath())) highest = actual; projected = projected.next();
else if (highest.getPath().isDecendantOf(actual.getPath())) highest = actual; projected = projected.next();