### Question:
BasicPath extends AbstractPath { public Path getAncestor( int degree ) { CheckArg.isNonNegative(degree, "degree"); if (degree == 0) return this; int endIndex = this.segments.size() - degree; if (endIndex == 0) return this.isAbsolute() ? RootPath.INSTANCE : null; if (endIndex < 0) { String msg = GraphI18n.pathAncestorDegreeIsInvalid.text(this.getString(), Inflector.getInstance().ordinalize(degree)); throw new InvalidPathException(msg); } return subpath(0, endIndex); } 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 shouldReturnNthDegreeAncestor() { assertThat(path.getAncestor(1), is(pathFactory.create("/mode:a/mode:b"))); assertThat(path.getAncestor(2), is(pathFactory.create("/mode:a"))); assertThat(path.getAncestor(3), is(ROOT)); }