Skip to content

Commit

Permalink
Issue #14625: fix inspection violation OptionalGetWithoutIsPresent Ja…
Browse files Browse the repository at this point in the history
…vaParserTest tAHSLCN
  • Loading branch information
MANISH-K-07 committed Apr 19, 2024
1 parent 174bccc commit 8161d55
Showing 1 changed file with 31 additions and 35 deletions.
66 changes: 31 additions & 35 deletions src/test/java/com/puppycrawl/tools/checkstyle/JavaParserTest.java
Original file line number Diff line number Diff line change
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,38 @@ 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")
.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");
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");
}
}

/**
Expand Down

0 comments on commit 8161d55

Please sign in to comment.