### Question:
BasicPath extends AbstractPath { public int size() { return this.segments.size(); } BasicPath( List<Segment> segments,
                      boolean absolute ); Path getAncestor( int degree ); List<Segment> getSegmentsList(); boolean isAbsolute(); boolean isNormalized(); boolean isRoot(); int size(); static final Path EMPTY_RELATIVE; static final Path SELF_PATH; static final Path PARENT_PATH; }### Answer:
@Test public void shouldCreatePathWithNoNamespacePrefixes() { path = pathFactory.create("/a/b/c/"); assertThat(path.size(), is(3)); assertThat(path, hasSegments(pathFactory, "a", "b", "c")); }
@Test public void shouldHaveSizeThatReflectsNumberOfSegments() { assertThat(path.size(), is(validSegmentsList.size())); }
@Test( expected = IndexOutOfBoundsException.class ) public void shouldFailToReturnSubpathWithoutEndingIndexIfStartingIndexIsEqualToOrLargerThanSize() { path = pathFactory.create("/mode:a/b/mode:c/../d/./mode:e/../.."); path.subpath(path.size() + 1); }
@Test( expected = IndexOutOfBoundsException.class ) public void shouldFailToReturnSubpathWithEndingIndexIfStartingIndexIsEqualToOrLargerThanSize() { path = pathFactory.create("/mode:a/b/mode:c/../d/./mode:e/../.."); path.subpath(path.size() + 1, path.size() + 2); }
@Test( expected = IndexOutOfBoundsException.class ) public void shouldFailToReturnSubpathIfEndingIndexIsEqualToOrLargerThanSize() { path = pathFactory.create("/mode:a/b/mode:c/../d/./mode:e/../.."); path.subpath(2, path.size() + 1); }
@Test public void shouldReturnSubpathIfValidStartingIndexAndEndingIndexAreProvided() { path = pathFactory.create("/mode:a/b/mode:c/../d/./mode:e/../.."); assertThat(path.subpath(0, path.size()), hasSegments(pathFactory, "mode:a", "b", "mode:c", "..", "d", ".", "mode:e", "..", "..")); assertThat(path.subpath(0, path.size()), is(path)); assertThat(path.subpath(0, path.size()), is(sameInstance(path))); assertThat(path.subpath(1, path.size()), hasSegments(pathFactory, "b", "mode:c", "..", "d", ".", "mode:e", "..", "..")); assertThat(path.subpath(2, path.size()), hasSegments(pathFactory, "mode:c", "..", "d", ".", "mode:e", "..", "..")); assertThat(path.subpath(3, path.size()), hasSegments(pathFactory, "..", "d", ".", "mode:e", "..", "..")); assertThat(path.subpath(4, path.size()), hasSegments(pathFactory, "d", ".", "mode:e", "..", "..")); assertThat(path.subpath(5, path.size()), hasSegments(pathFactory, ".", "mode:e", "..", "..")); assertThat(path.subpath(6, path.size()), hasSegments(pathFactory, "mode:e", "..", "..")); assertThat(path.subpath(7, path.size()), hasSegments(pathFactory, "..", "..")); assertThat(path.subpath(8, path.size()), hasSegments(pathFactory, "..")); assertThat(path.subpath(0, 2), hasSegments(pathFactory, "mode:a", "b")); assertThat(path.subpath(1, 2), hasSegments(pathFactory, "b")); assertThat(path.subpath(1, 5), hasSegments(pathFactory, "b", "mode:c", "..", "d")); assertThat(path.subpath(2, 5), hasSegments(pathFactory, "mode:c", "..", "d")); assertThat(path.subpath(3, 5), hasSegments(pathFactory, "..", "d")); }