protected boolean computeSimpleProjection( List<Rule> rules ) { // Get the set of repository paths for the rules, and see if they overlap ... Set<Path> repositoryPaths = new HashSet<Path>(); for (Rule rule : rules) { if (rule instanceof PathRule) { PathRule pathRule = (PathRule)rule; Path repoPath = pathRule.getPathInRepository(); if (!repositoryPaths.isEmpty()) { if (repositoryPaths.contains(repoPath)) return false; for (Path path : repositoryPaths) { if (path.isAtOrAbove(repoPath)) return false; if (repoPath.isAtOrAbove(path)) return false; } } repositoryPaths.add(repoPath); } else { return false; } } return true; }
@Test( expected = IllegalArgumentException.class ) public void shouldFailForAtOrAboveNullPath() { path.isAtOrAbove(null); }
@Test( expected = IllegalArgumentException.class ) public void shouldFailForAtOrAboveNullPath() { path.isAtOrAbove(null); }
/** * @param pathInSource * @return true if the source path is included by this rule */ protected boolean includes( Path pathInSource ) { // Check whether the path is outside the source-specific path ... if (pathInSource != null && this.sourcePath.isAtOrAbove(pathInSource)) { // The path is inside the source-specific region, so check the exceptions ... List<Path> exceptions = getExceptionsToRule(); if (exceptions.size() != 0) { Path subpathInSource = pathInSource.relativeTo(this.sourcePath); if (subpathInSource.size() != 0) { for (Path exception : exceptions) { if (subpathInSource.isAtOrBelow(exception)) return false; } } } return true; } return false; }
@Test public void shouldConsiderNodeToBeAtOrAboveItself() { assertThat(path.isAtOrAbove(path), is(true)); }
@Test public void shouldConsiderNodeToBeAtOrAboveItself() { assertThat(path.isAtOrAbove(path), is(true)); }
@Test public void shouldConsiderAncestorToBeAtOrAboveTheDecendant() { 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"); for (int i = 1; i < path1.size(); ++i) { assertThat(path1.getAncestor(i).isAtOrAbove(path1), is(true)); } for (int i = 1; i < path2.size(); ++i) { assertThat(path2.getAncestor(i).isAtOrAbove(path2), is(true)); } for (int i = 1; i < path3.size(); ++i) { assertThat(path3.getAncestor(i).isAtOrAbove(path3), is(true)); } for (int i = 1; i < path4.size(); ++i) { assertThat(path4.getAncestor(i).isAtOrAbove(path4), is(true)); } }
@Test public void shouldConsiderAncestorToBeAtOrAboveTheDecendant() { 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"); for (int i = 1; i < path1.size(); ++i) { assertThat(path1.getAncestor(i).isAtOrAbove(path1), is(true)); } for (int i = 1; i < path2.size(); ++i) { assertThat(path2.getAncestor(i).isAtOrAbove(path2), is(true)); } for (int i = 1; i < path3.size(); ++i) { assertThat(path3.getAncestor(i).isAtOrAbove(path3), is(true)); } for (int i = 1; i < path4.size(); ++i) { assertThat(path4.getAncestor(i).isAtOrAbove(path4), is(true)); } }
@Test public void shouldNotConsiderDecendantToBeAtOrAboveTheAncestor() { 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"); for (int i = 1; i < path1.size(); ++i) { assertThat(path1.isAtOrAbove(path1.getAncestor(i)), is(false)); } for (int i = 1; i < path2.size(); ++i) { assertThat(path2.isAtOrAbove(path2.getAncestor(i)), is(false)); } for (int i = 1; i < path3.size(); ++i) { assertThat(path3.isAtOrAbove(path3.getAncestor(i)), is(false)); } for (int i = 1; i < path4.size(); ++i) { assertThat(path4.isAtOrAbove(path4.getAncestor(i)), is(false)); } }
@Test public void shouldNotConsiderDecendantToBeAtOrAboveTheAncestor() { 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"); for (int i = 1; i < path1.size(); ++i) { assertThat(path1.isAtOrAbove(path1.getAncestor(i)), is(false)); } for (int i = 1; i < path2.size(); ++i) { assertThat(path2.isAtOrAbove(path2.getAncestor(i)), is(false)); } for (int i = 1; i < path3.size(); ++i) { assertThat(path3.isAtOrAbove(path3.getAncestor(i)), is(false)); } for (int i = 1; i < path4.size(); ++i) { assertThat(path4.isAtOrAbove(path4.getAncestor(i)), is(false)); } }