@Test public void shouldAlreadyBeNormalizedIfPathContainsNoParentOrSelfReferences() { assertThat(pathFactory.create("/a/b/c/d/e").isNormalized(), is(true)); assertThat(pathFactory.create("a/b/c/d/e").isNormalized(), is(true)); assertThat(pathFactory.create("a").isNormalized(), is(true)); assertThat(pathFactory.create("/a").isNormalized(), is(true)); assertThat(ROOT.isNormalized(), is(true)); }
@Test public void shouldNotBeNormalizedIfPathContainsParentOrSelfReferences() { assertThat(pathFactory.create("/a/b/c/../d/./e/../..").isNormalized(), is(false)); assertThat(pathFactory.create("a/b/c/../d/./e/../..").isNormalized(), is(false)); assertThat(pathFactory.create("a/b/c/./d").isNormalized(), is(false)); assertThat(pathFactory.create("/a/b/c/../d").isNormalized(), is(false)); assertThat(pathFactory.create(".").isNormalized(), is(false)); assertThat(pathFactory.create("/.").isNormalized(), is(false)); }
@Test public void shouldConsiderAsNotNormalizedAnAbsolutePathThatBeginsWithParentReference() { List<Path.Segment> segments = new ArrayList<Path.Segment>(); segments.add(Path.PARENT_SEGMENT); segments.add(pathFactory.createSegment("nonParentSegment")); segments.add(pathFactory.createSegment("nonParentSegment2")); path = new BasicPath(segments, true); assertThat(path.isAbsolute(), is(true)); assertThat(path.isNormalized(), is(false)); }
@Test public void shouldConsiderAsNotNormalizedAnAbsolutePathWithParentSegmentAtFront() { List<Path.Segment> segments = new ArrayList<Path.Segment>(); segments.add(Path.PARENT_SEGMENT); segments.addAll(validSegmentsList); path = new BasicPath(segments, true); assertThat(path.isAbsolute(), is(true)); assertThat(path.isNormalized(), is(false)); assertThat(path.getSegmentsList(), is(segments)); assertThat(path.size(), is(segments.size())); }
@Test public void shouldConsiderAsNotNormalizedAnAbsolutePathWithAllParentReferences() { List<Path.Segment> segments = new ArrayList<Path.Segment>(); for (int i = 0; i != 10; ++i) { segments.add(Path.PARENT_SEGMENT); } path = new BasicPath(segments, true); assertThat(path.isAbsolute(), is(true)); assertThat(path.isNormalized(), is(false)); assertThat(path.getSegmentsList(), is(segments)); assertThat(path.size(), is(segments.size())); }
@Test public void shouldCreateAbsolutePathWithParentSegment() { validSegmentsList.add(Path.PARENT_SEGMENT); path = new BasicPath(validSegmentsList, true); assertThat(path.isAbsolute(), is(true)); assertThat(path.isNormalized(), is(false)); assertThat(path.getSegmentsList(), is(validSegmentsList)); assertThat(path.size(), is(validSegmentsList.size())); }
@Test public void shouldCreateRelativePathWithSelfSegment() { validSegmentsList.add(Path.SELF_SEGMENT); path = new BasicPath(validSegmentsList, false); assertThat(path.isAbsolute(), is(false)); assertThat(path.isNormalized(), is(false)); assertThat(path.getSegmentsList(), is(validSegmentsList)); assertThat(path.size(), is(validSegmentsList.size())); }
@Test public void shouldReturnRootPathAsTheNormalizedPathForAnAbsolutePathWithZeroSegmentsAfterParentAndSelfReferencesRemoved() { // "/a/../b/../c/.." => "/" path = pathFactory.create("/a/../b/../c/../"); assertThat(path.isNormalized(), is(false)); assertThat(path.getNormalizedPath(), is(ROOT)); }
@Test public void shouldCreateAbsolutePathWithSelfSegment() { validSegmentsList.add(Path.SELF_SEGMENT); path = new BasicPath(validSegmentsList, true); assertThat(path.isAbsolute(), is(true)); assertThat(path.isNormalized(), is(false)); assertThat(path.getSegmentsList(), is(validSegmentsList)); assertThat(path.size(), is(validSegmentsList.size())); }
@Test public void shouldReturnRootPathAsTheNormalizedPathForAnAbsolutePathWithZeroSegmentsAfterParentAndSelfReferencesRemoved() { // "/a/../b/../c/.." => "/" path = pathFactory.create("/a/../b/../c/../"); assertThat(path.isNormalized(), is(false)); assertThat(path.getNormalizedPath(), is(ROOT)); }
@Test public void shouldCreateRelativePathWithSelfSegment() { validSegmentsList.add(Path.SELF_SEGMENT); path = new BasicPath(validSegmentsList, false); assertThat(path.isAbsolute(), is(false)); assertThat(path.isNormalized(), is(false)); assertThat(path.getSegmentsList(), is(validSegmentsList)); assertThat(path.size(), is(validSegmentsList.size())); }
@Test public void shouldCreateAbsolutePathFromListOfValidSegments() { path = new BasicPath(validSegmentsList, true); assertThat(path.isAbsolute(), is(true)); assertThat(path.isNormalized(), is(true)); assertThat(path.getSegmentsList(), is(validSegmentsList)); assertThat(path.size(), is(validSegmentsList.size())); }
@Test public void shouldCreateRelativePathFromListOfValidSegments() { path = new BasicPath(validSegmentsList, false); assertThat(path.isAbsolute(), is(false)); assertThat(path.isNormalized(), is(true)); assertThat(path.getSegmentsList(), is(validSegmentsList)); assertThat(path.size(), is(validSegmentsList.size())); }
@Test public void shouldConsiderAsNotNormalizedAPathWithParentSegmentAtEnd() { path = new ChildPath(parent, Path.PARENT_SEGMENT); assertThat(path.isAbsolute(), is(parent.isAbsolute())); assertThat(path.isNormalized(), is(false)); }
@Test public void shouldNotHaveAnyParentOrSelfReferencesInTheNormalizedPathOfAnAbsolutePath() { path = pathFactory.create("/a/b/c/../d/./e/../.."); assertThat(path.isNormalized(), is(false)); assertThat(path.getNormalizedPath(), hasSegments(pathFactory, "a", "b")); assertThat(path.getNormalizedPath().isAbsolute(), is(true)); assertThat(path.getNormalizedPath().isNormalized(), is(true)); }
@Test public void shouldConsiderAsNormalizedARelativePathWithParentSegmentAtFront() { parent = path("../../a/b/c/d"); path = new ChildPath(parent, segment("e")); assertThat(path.isNormalized(), is(true)); }
@Test public void shouldReturnNormalizedPathForTheCanonicalPathOfAbsolutePath() { path = pathFactory.create("/a/b/c/../d/./e/../.."); assertThat(path.isNormalized(), is(false)); assertThat(path.isAbsolute(), is(true)); assertThat(path.getCanonicalPath(), hasSegments(pathFactory, "a", "b")); assertThat(path.getCanonicalPath().isAbsolute(), is(true)); assertThat(path.getCanonicalPath().isNormalized(), is(true)); }
@Test public void shouldReturnNormalizedPathForTheCanonicalPathOfAbsolutePath() { path = pathFactory.create("/a/b/c/../d/./e/../.."); assertThat(path.isNormalized(), is(false)); assertThat(path.isAbsolute(), is(true)); assertThat(path.getCanonicalPath(), hasSegments(pathFactory, "a", "b")); assertThat(path.getCanonicalPath().isAbsolute(), is(true)); assertThat(path.getCanonicalPath().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)); }
@Test public void shouldConstructRelativePath() { assertThat(pathFactory.create("a/b/c").isAbsolute(), is(false)); assertThat(pathFactory.create("a/b/c").isNormalized(), is(true)); assertThat(pathFactory.create("a/b/c").size(), is(3)); assertThat(pathFactory.create("a/b/c").getString(namespaceRegistry), is("a/b/c")); }