KeyTree { public KeyTree.Node add(final String path) { KeyTree.Node parent = this.root; String key = path; if (path != null) { final int i = path.lastIndexOf('.'); if (i >= 0) { final String parentPath = path.substring(0, i); key = path.substring(i + 1); parent = this.get(parentPath); if (parent == null) { parent = this.add(parentPath); } } } return parent.add(key); } KeyTree(final YamlConfigurationOptions options); KeyTree.Node add(final String path); KeyTree.Node findParent(final int indent); KeyTree.Node get(final String path); Set<String> keys(); Set<Map.Entry<String, KeyTree.Node>> entries(); @Override String toString();  }
@Test void add() { final YamlConfiguration configuration = new YamlConfiguration(); final YamlConfigurationOptions options = new TestYamlConfigurationOptions(configuration); final KeyTree tree = new KeyTree(options); final String defaultnodekey = "defaultnodekey"; final String nodewithcommentkey = "nodewithcommentkey"; tree.add(defaultnodekey); tree.add(nodewithcommentkey); final KeyTree.Node defaultnode = tree.get(defaultnodekey); final KeyTree.Node nodewithcomment = tree.get(nodewithcommentkey); final String commentOfNodewithcomment = "Comment of nodewithcomment"; final String sideCommentOfNodewithcomment = "Side comment of nodewithcomment"; nodewithcomment.setComment(commentOfNodewithcomment); nodewithcomment.setSideComment(sideCommentOfNodewithcomment); MatcherAssert.assertThat( "The node has a root!", defaultnode.getIndentation(), new IsEqual<>(0) ); MatcherAssert.assertThat( "The node's name is not correct!", defaultnode.getName(), new IsEqual<>(defaultnodekey) ); MatcherAssert.assertThat( "There is a comment!", defaultnode.getComment(), new IsNull<>() ); MatcherAssert.assertThat( "There is a side comment!", defaultnode.getSideComment(), new IsNull<>() ); MatcherAssert.assertThat( "The node has a root!", nodewithcomment.getIndentation(), new IsEqual<>(0) ); MatcherAssert.assertThat( "The node's name is not correct!", nodewithcomment.getName(), new IsEqual<>(nodewithcommentkey) ); MatcherAssert.assertThat( "There is not a a comment!", nodewithcomment.getComment(), new IsEqual<>(commentOfNodewithcomment) ); MatcherAssert.assertThat( "There is not a side comment!", nodewithcomment.getSideComment(), new IsEqual<>(sideCommentOfNodewithcomment) ); }