Skip to content

Commit

Permalink
Issue checkstyle#14625: fix inspection violation OptionalGetWithoutIs…
Browse files Browse the repository at this point in the history
…Present JavaParserTest tAHSLCN
  • Loading branch information
MANISH-K-07 committed Apr 20, 2024
1 parent bb56e9d commit d79c161
Showing 1 changed file with 32 additions and 34 deletions.
66 changes: 32 additions & 34 deletions src/test/java/com/puppycrawl/tools/checkstyle/JavaParserTest.java
Expand Up @@ -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 =
Expand All @@ -119,36 +113,40 @@ public void testAppendHiddenSingleLineCommentNodes() throws Exception {

final Optional<DetailAST> 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");
}
}

/**
Expand Down

0 comments on commit d79c161

Please sign in to comment.