1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package com.puppycrawl.tools.checkstyle.utils;
21
22 import static com.google.common.truth.Truth.assertWithMessage;
23 import static com.puppycrawl.tools.checkstyle.internal.utils.TestUtil.isUtilsClassHasPrivateConstructor;
24
25 import org.junit.jupiter.api.Test;
26
27 import com.puppycrawl.tools.checkstyle.api.DetailAST;
28 import com.puppycrawl.tools.checkstyle.api.TokenTypes;
29
30 public class ParserUtilTest {
31
32 @Test
33 public void testIsProperUtilsClass() throws ReflectiveOperationException {
34 assertWithMessage("Constructor is not private")
35 .that(isUtilsClassHasPrivateConstructor(ParserUtil.class))
36 .isTrue();
37 }
38
39 @Test
40 public void testCreationOfFakeCommentBlock() {
41 final DetailAST testCommentBlock =
42 ParserUtil.createBlockCommentNode("test_comment");
43 assertWithMessage("Invalid token type")
44 .that(testCommentBlock.getType())
45 .isEqualTo(TokenTypes.BLOCK_COMMENT_BEGIN);
46 assertWithMessage("Invalid text")
47 .that(testCommentBlock.getText())
48 .isEqualTo("/*");
49 assertWithMessage("Invalid line number")
50 .that(testCommentBlock.getLineNo())
51 .isEqualTo(0);
52
53 final DetailAST contentCommentBlock = testCommentBlock.getFirstChild();
54 assertWithMessage("Invalid token type")
55 .that(contentCommentBlock.getType())
56 .isEqualTo(TokenTypes.COMMENT_CONTENT);
57 assertWithMessage("Invalid text")
58 .that(contentCommentBlock.getText())
59 .isEqualTo("*test_comment");
60 assertWithMessage("Invalid line number")
61 .that(contentCommentBlock.getLineNo())
62 .isEqualTo(0);
63 assertWithMessage("Invalid column number")
64 .that(contentCommentBlock.getColumnNo())
65 .isEqualTo(-1);
66
67 final DetailAST endCommentBlock = contentCommentBlock.getNextSibling();
68 assertWithMessage("Invalid token type")
69 .that(endCommentBlock.getType())
70 .isEqualTo(TokenTypes.BLOCK_COMMENT_END);
71 assertWithMessage("Invalid text")
72 .that(endCommentBlock.getText())
73 .isEqualTo("*/");
74 }
75 }