diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/JavaParserTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/JavaParserTest.java index bb0686a5bd6..62678de9743 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/JavaParserTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/JavaParserTest.java @@ -105,12 +105,6 @@ public void testAppendHiddenBlockCommentNodes() throws Exception { .isEqualTo(1); } - /** - * Temporary java doc. - * - * @noinspection OptionalGetWithoutIsPresent - * @noinspectionreason OptionalGetWithoutIsPresent - until issue #14625 - */ @Test public void testAppendHiddenSingleLineCommentNodes() throws Exception { final DetailAST root = @@ -119,36 +113,40 @@ public void testAppendHiddenSingleLineCommentNodes() throws Exception { final Optional singleLineComment = TestUtil.findTokenInAstByPredicate(root, ast -> ast.getType() == TokenTypes.SINGLE_LINE_COMMENT); - assertWithMessage("Single line comment should be present") + + if (singleLineComment.isPresent()) { + final DetailAST comment = singleLineComment.get(); + + assertWithMessage("Unexpected line number") + .that(comment.getLineNo()) + .isEqualTo(13); + assertWithMessage("Unexpected column number") + .that(comment.getColumnNo()) + .isEqualTo(0); + assertWithMessage("Unexpected comment content") + .that(comment.getText()) + .isEqualTo("//"); + + final DetailAST commentContent = comment.getFirstChild(); + + assertWithMessage("Unexpected token type") + .that(commentContent.getType()) + .isEqualTo(TokenTypes.COMMENT_CONTENT); + assertWithMessage("Unexpected line number") + .that(commentContent.getLineNo()) + .isEqualTo(13); + assertWithMessage("Unexpected column number") + .that(commentContent.getColumnNo()) + .isEqualTo(2); + assertWithMessage("Unexpected comment content") + .that(commentContent.getText()) + .startsWith(" inline comment"); + } + else { + assertWithMessage("Single line comment should be present") .that(singleLineComment.isPresent()) .isTrue(); - - final DetailAST comment = singleLineComment.get(); - - assertWithMessage("Unexpected line number") - .that(comment.getLineNo()) - .isEqualTo(13); - assertWithMessage("Unexpected column number") - .that(comment.getColumnNo()) - .isEqualTo(0); - assertWithMessage("Unexpected comment content") - .that(comment.getText()) - .isEqualTo("//"); - - final DetailAST commentContent = comment.getFirstChild(); - - assertWithMessage("Unexpected token type") - .that(commentContent.getType()) - .isEqualTo(TokenTypes.COMMENT_CONTENT); - assertWithMessage("Unexpected line number") - .that(commentContent.getLineNo()) - .isEqualTo(13); - assertWithMessage("Unexpected column number") - .that(commentContent.getColumnNo()) - .isEqualTo(2); - assertWithMessage("Unexpected comment content") - .that(commentContent.getText()) - .startsWith(" inline comment"); + } } /**