/** * {@inheritDoc} */ public Path resolveAgainst( Path absolutePath ) { CheckArg.isNotNull(absolutePath, "absolute path"); return absolutePath.resolve(this); }
@Test( expected = InvalidPathException.class ) public void shouldNotResolveRelativePathUsingAnAbsolutePath() { Path other = mock(Path.class); when(other.isAbsolute()).thenReturn(true); root.resolve(other); }
@Test public void shouldResolveAllRelativePathsToTheirAbsolutePath() { List<Path.Segment> segments = new ArrayList<Path.Segment>(); segments.add(new BasicPathSegment(new BasicName("http://example.com", "a"))); Path other = mock(Path.class); when(other.isAbsolute()).thenReturn(false); when(other.getSegmentsList()).thenReturn(segments); when(other.getNormalizedPath()).thenReturn(other); Path resolved = root.resolve(other); assertThat(resolved.getSegmentsList(), is(segments)); assertThat(resolved.isAbsolute(), is(true)); }
@Test public void shouldResolveRelativePaths() { path = pathFactory.create("/a/b/c/d/e/f"); assertThat(path.resolve(pathFactory.create("../../../../../..")), is(ROOT)); assertThat(path.resolve(pathFactory.create("../..")), is(path.getParent().getParent())); assertThat(path.resolve(pathFactory.create("../..")), hasSegments(pathFactory, "a", "b", "c", "d")); assertThat(path.resolve(pathFactory.create("../x/../y/../z/..")), is(path.getParent())); assertThat(path.resolve(pathFactory.create("../x/../y/../z/..")), hasSegments(pathFactory, "a", "b", "c", "d", "e")); assertThat(path.resolve(pathFactory.create("../x")), hasSegments(pathFactory, "a", "b", "c", "d", "e", "x")); }
@Test public void shouldResolveRelativePaths() { path = pathFactory.create("/a/b/c/d/e/f"); assertThat(path.resolve(pathFactory.create("../../../../../..")), is(sameInstance(ROOT))); assertThat(path.resolve(pathFactory.create("../..")), is(path.getParent().getParent())); assertThat(path.resolve(pathFactory.create("../..")), hasSegments(pathFactory, "a", "b", "c", "d")); assertThat(path.resolve(pathFactory.create("../x/../y/../z/..")), is(path.getParent())); assertThat(path.resolve(pathFactory.create("../x/../y/../z/..")), hasSegments(pathFactory, "a", "b", "c", "d", "e")); assertThat(path.resolve(pathFactory.create("../x")), hasSegments(pathFactory, "a", "b", "c", "d", "e", "x")); }
@Test( expected = InvalidPathException.class ) public void shouldNotResolveRelativePathUsingAnAbsolutePath() { path = pathFactory.create("/a/b/c/d"); path.resolve(pathFactory.create("/e/f")); }
@Test( expected = InvalidPathException.class ) public void shouldNotResolveRelativePathUsingAnAbsolutePath() { path = pathFactory.create("/a/b/c/d"); path.resolve(pathFactory.create("/e/f")); }
@Test public void shouldResolveRelativePathToAbsolutePath() { path = pathFactory.create("/a/b/c/d"); path2 = path.resolve(pathFactory.create("../../e/f")); assertThat(path2, is(pathFactory.create("/a/b/e/f"))); assertThat(path2.isAbsolute(), is(true)); assertThat(path2.isNormalized(), is(true)); }
@Test public void shouldResolveRelativePathToAbsolutePath() { path = pathFactory.create("/a/b/c/d"); path2 = path.resolve(pathFactory.create("../../e/f")); assertThat(path2, is(pathFactory.create("/a/b/e/f"))); assertThat(path2.isAbsolute(), is(true)); assertThat(path2.isNormalized(), is(true)); }
Path absolutePath = targetNodePath.isAbsolute() ? targetNodePath : outputNodePath.resolve(targetNodePath);