Paths { static Path parse(String path, boolean resolveJsonPointerEscapes) { path = Strings.trim(path, (c) -> c < ' ' || c == '/'); if (path.length() == 0) { return RootPath.INSTANCE; } String[] segments = PATH_SEPARATOR_PATTERN.split(path); if (segments.length == 1) { return new SingleSegmentPath(parseSegment(segments[0], resolveJsonPointerEscapes)); } if (resolveJsonPointerEscapes) { for (int i = 0; i != segments.length; ++i) { segments[i] = parseSegment(segments[i], true); } } return new MultiSegmentPath(segments); } private  Paths();   }
@Test public void shouldParseRootPath() { path = parse("/"); assertThat(path.isRoot()).isTrue(); assertThat(path.isSingle()).isFalse(); assertThat(path.size()).isEqualTo(0); }
@Test public void shouldParseSingleRelativePath() { path = parse("a"); assertThat(path.isRoot()).isFalse(); assertThat(path.isSingle()).isTrue(); assertThat(path.size()).isEqualTo(1); assertThat(path.segment(0)).isEqualTo("a"); }
@Test public void shouldParseSingleAbsolutePath() { path = parse("/a"); assertThat(path.isRoot()).isFalse(); assertThat(path.isSingle()).isTrue(); assertThat(path.size()).isEqualTo(1); assertThat(path.segment(0)).isEqualTo("a"); }
@Test public void shouldParseDoubleRelativePath() { path = parse("a/b"); assertThat(path.isRoot()).isFalse(); assertThat(path.isSingle()).isFalse(); assertThat(path.size()).isEqualTo(2); assertThat(path.segment(0)).isEqualTo("a"); assertThat(path.segment(1)).isEqualTo("b"); }
@Test public void shouldParseDoubleAbsolutePath() { path = parse("/a/b"); assertThat(path.isRoot()).isFalse(); assertThat(path.isSingle()).isFalse(); assertThat(path.size()).isEqualTo(2); assertThat(path.segment(0)).isEqualTo("a"); assertThat(path.segment(1)).isEqualTo("b"); }
@Test public void shouldParseMultiRelativePath() { path = parse("a/b"); assertThat(path.isRoot()).isFalse(); assertThat(path.isSingle()).isFalse(); assertThat(path.size()).isEqualTo(2); assertThat(path.segment(0)).isEqualTo("a"); assertThat(path.segment(1)).isEqualTo("b"); }
@Test public void shouldParseMultiAbsolutePath() { path = parse("/a/b/c/d/e"); assertThat(path.isRoot()).isFalse(); assertThat(path.isSingle()).isFalse(); assertThat(path.size()).isEqualTo(5); assertThat(path.segment(0)).isEqualTo("a"); assertThat(path.segment(1)).isEqualTo("b"); assertThat(path.segment(2)).isEqualTo("c"); assertThat(path.segment(3)).isEqualTo("d"); assertThat(path.segment(4)).isEqualTo("e"); }