CommentMapper implements Commentable { @Override public void setComment(final String path, String comment, final CommentType type) { KeyTree.Node node = this.getNode(path); if (node == null) { node = this.keyTree.add(path); } if (comment == null || comment.isEmpty()) { this.setComment(node, null, type); } else if (comment.matches("\n+")) { this.setComment(node, comment, type); } else { comment = Commentable.COMMENT_PREFIX + comment; comment = comment.replaceAll("[ \\t]*\n", "\n" + Commentable.COMMENT_PREFIX); if (type == CommentType.BLOCK) { node.setComment(this.indent(comment, node.getIndentation())); } else { node.setSideComment(" " + comment); } } } CommentMapper(final YamlConfigurationOptions options); @Override void setComment(final String path, String comment, final CommentType type); @Override String getComment(final String path, final CommentType type);  }
@Test void setComment() { final YamlConfiguration configuration = new YamlConfiguration(); final YamlConfigurationOptions options = new TestYamlConfigurationOptions(configuration); final CommentMapper mapper = new CommentMapper(options); final String test_comment = "test comment"; mapper.setComment("test", test_comment); final String test_side_comment = "test side comment"; mapper.setComment("test", test_side_comment, CommentType.SIDE); final String comment = mapper.getComment("test"); final String sidecomment = mapper.getComment("test", CommentType.SIDE); MatcherAssert.assertThat( "Comment couldn't set!", comment, new IsEqual<>(test_comment) ); MatcherAssert.assertThat( "Side comment couldn't set!", sidecomment, new IsEqual<>(test_side_comment) ); }