### Question:
GraphName { public static GraphName of(String name) { return new GraphName(canonicalize(name)); } private  GraphName(String name); static GraphName newAnonymous(); static GraphName root(); static GraphName empty(); static GraphName of(String name); boolean isGlobal(); boolean isRoot(); boolean isEmpty(); boolean isPrivate(); boolean isRelative(); GraphName getParent(); GraphName getBasename(); GraphName toRelative(); GraphName toGlobal(); GraphName join(GraphName other); GraphName join(String other); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); static final String VALID_GRAPH_NAME_REGEXP; static final Pattern VALID_GRAPH_NAME_PATTERN; }### Answer:
@Test public void testValidNames() { String[] valid = { "", "abc", "ab7", "ab7_kdfJKSDJFGkd", "/abc", "/", "~private", "~private/something", "/global", "/global/", "/global/local" }; for (String v : valid) { GraphName.of(v); } }
@Test public void testInvalidNames() { final String[] illegalChars = { "=", "-", "(", ")", "*", "%", "^" }; for (String i : illegalChars) { try { GraphName.of("good" + i); fail("Bad name not caught: " + i); } catch (RuntimeException e) { } } final String[] illegalNames = { "/~private", "5foo" }; for (String i : illegalNames) { try { GraphName.of(i); fail("Bad name not caught" + i); } catch (RuntimeException e) { } } }
@Test public void testCanonicalizeName() { assertGraphNameEquals("", GraphName.of("")); assertGraphNameEquals("/", GraphName.of("/")); assertGraphNameEquals("/", GraphName.of(" assertGraphNameEquals("/", GraphName.of(" assertGraphNameEquals("foo", GraphName.of("foo")); assertGraphNameEquals("foo", GraphName.of("foo/")); assertGraphNameEquals("foo", GraphName.of("foo assertGraphNameEquals("/foo", GraphName.of("/foo")); assertGraphNameEquals("/foo", GraphName.of("/foo/")); assertGraphNameEquals("/foo", GraphName.of("/foo assertGraphNameEquals("/foo/bar", GraphName.of("/foo/bar")); assertGraphNameEquals("/foo/bar", GraphName.of("/foo/bar/")); assertGraphNameEquals("/foo/bar", GraphName.of("/foo/bar assertGraphNameEquals("~foo", GraphName.of("~foo")); assertGraphNameEquals("~foo", GraphName.of("~foo/")); assertGraphNameEquals("~foo", GraphName.of("~foo assertGraphNameEquals("~foo", GraphName.of("~/foo")); }