ImmutableListPathCore implements PathCore<ImmutableListPathCore> { @Override public ImmutableListPathCore subpath(int beginIndex, int endIndex) { checkPositionIndex(endIndex, getNameCount(), "endIndex"); checkElementIndex(beginIndex, endIndex, "beginIndex"); return new ImmutableListPathCore(null, path.subList(beginIndex, endIndex)); } ImmutableListPathCore(@Nullable String root, Iterable<String> path); static Parser parser(String separator); static Parser namedRootParser(String separator, NamedRootFormat format, String rootId); @Override boolean isAbsolute(); @Override ImmutableListPathCore getRoot(); @Override ImmutableListPathCore getFileName(); @Override ImmutableListPathCore getParent(); @Override int getNameCount(); @Override ImmutableListPathCore getName(int index); @Override ImmutableListPathCore subpath(int beginIndex, int endIndex); @Override boolean startsWith(ImmutableListPathCore other); @Override boolean endsWith(ImmutableListPathCore other); @Override ImmutableListPathCore normalize(); @Override ImmutableListPathCore resolve(ImmutableListPathCore other); @Override ImmutableListPathCore resolveSibling(ImmutableListPathCore other); @Override ImmutableListPathCore relativize(ImmutableListPathCore other); @Override String toPathString(String separator); @Override String toString(); @Override int compareTo(ImmutableListPathCore other); @Override boolean equals(Object obj); @Override int hashCode(); @Nullable String getRootString(); ImmutableList<String> getPathSegments();  }
@Test public void invalidSubpathIndicesThrowsException() { try { absolute.subpath(-1, 2); fail("negative begin index allowed"); } catch (IndexOutOfBoundsException | IllegalArgumentException expected) { } try { absolute.subpath(3, 4); fail("begin index == length allowed"); } catch (IndexOutOfBoundsException | IllegalArgumentException expected) { } try { absolute.subpath(2, 0); fail("end index < begin index allowed"); } catch (IndexOutOfBoundsException | IllegalArgumentException expected) { } try { absolute.subpath(0, 4); fail("end index > length allowed"); } catch (IndexOutOfBoundsException | IllegalArgumentException expected) { } }
@Test public void fullSubpathIsEqualToPath() { ImmutableListPathCore sub = relative.subpath(0, 3); assertEquals("subpath is not equal to path", relative, sub); }
@Test public void subpath() { ImmutableListPathCore sub = relative.subpath(1, 3); assertThat(sub, hasPath("to", "file")); }