assertThat(path, hasSegments(pathFactory, "a", "b", "c"));
}
@Test
public void shouldConvertPathToString() {
TextEncoder encoder = new Jsr283Encoder();
TextEncoder delimEncoder = new TextEncoder() {
public String encode( String text ) {
if ("/".equals(text)) return "\\/";
if (":".equals(text)) return "\\:";
if ("{".equals(text)) return "\\{";
if ("}".equals(text)) return "\\}";
return text;
}
};
Path path = pathFactory.create("a/b/c");
assertThat(path.getString(namespaceRegistry), is("a/b/c"));
assertThat(path.getString(namespaceRegistry, encoder), is("a/b/c"));
assertThat(path.getString(namespaceRegistry, encoder, delimEncoder), is("a\\/b\\/c"));
path = pathFactory.create("/a/b/c");
assertThat(path.getString(namespaceRegistry), is("/a/b/c"));
assertThat(path.getString(namespaceRegistry, encoder), is("/a/b/c"));
assertThat(path.getString(namespaceRegistry, encoder, delimEncoder), is("\\/a\\/b\\/c"));
path = pathFactory.create("/dna:a/b/c");
assertThat(path.getString(encoder), is("/{" + encoder.encode(DnaLexicon.Namespace.URI) + "}a/{}b/{}c"));
assertThat(path.getString(null, encoder, delimEncoder), is("\\/\\{" + encoder.encode(DnaLexicon.Namespace.URI)
+ "\\}a\\/\\{\\}b\\/\\{\\}c"));
assertThat(path.getString(namespaceRegistry), is("/dna:a/b/c"));
assertThat(path.getString(namespaceRegistry, encoder), is("/dna:a/b/c"));
assertThat(path.getString(namespaceRegistry, encoder, delimEncoder), is("\\/dna\\:a\\/b\\/c"));
}