CommentConventionCheck extends DoubleDispatchVisitorCheck { @VisibleForTesting void setStartingCommentToken(String startingCommentToken) { this.startingCommentToken = startingCommentToken; }  @Override void visitProperties(PropertiesTree tree); @Override void visitComment(SyntaxTrivia trivia); @Override void validateParameters();  }
@Test public void should_only_contain_comments_starting_with_exclamation_mark_token_and_not_raise_issues() { check.setStartingCommentToken("!"); JavaPropertiesCheckVerifier.verify(check, CheckTestUtils.getTestFile("comment-convention/commentsExclamationMarkOnly.properties")); }
@Test public void should_contain_comments_starting_with_hash_token_and_raise_issues() { check.setStartingCommentToken("!"); JavaPropertiesCheckVerifier.verify(check, CheckTestUtils.getTestFile("comment-convention/commentsExclamationMarkAndHash.properties")); }
@Test public void should_contain_comments_with_missing_whitespace_and_raise_some_issues_hash_token() { check.setStartingCommentToken("#"); JavaPropertiesCheckVerifier.issues(check, CheckTestUtils.getTestFile("comment-convention/commentsHashMissingWhitespace.properties")) .next().atLine(2).withMessage("Add a whitespace after the starting comment token.") .next().atLine(3).withMessage("Add a whitespace after the starting comment token.") .noMore(); }
@Test public void should_contain_comments_with_missing_whitespace_and_raise_some_issues_exclamation_mark_token() { check.setStartingCommentToken("!"); JavaPropertiesCheckVerifier.issues(check, CheckTestUtils.getTestFile("comment-convention/commentsExclamationMarkMissingWhitespace.properties")) .next().atLine(2).withMessage("Add a whitespace after the starting comment token.") .next().atLine(3).withMessage("Add a whitespace after the starting comment token.") .noMore(); }
@Test public void should_throw_an_illegal_state_exception_as_the_starting_comment_token_parameter_is_not_valid() { try { check.setStartingCommentToken("abc"); JavaPropertiesCheckVerifier.verify(check, CheckTestUtils.getTestFile("comment-convention/commentsHashOnly.properties")); } catch (IllegalStateException e) { assertThat(e.getMessage()).isEqualTo("Check jproperties:comment-convention (All comments should be formatted consistently): " + "startingCommentToken parameter is not valid.\nActual: 'abc'\nExpected: '#' or '!'"); } }