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.checks;
21
22 import static com.google.common.truth.Truth.assertWithMessage;
23 import static com.puppycrawl.tools.checkstyle.checks.MultilineCommentLeadingAsteriskPresenceCheck.MSG_MISSING_ASTERISK;
24
25 import org.junit.jupiter.api.Test;
26
27 import com.puppycrawl.tools.checkstyle.AbstractModuleTestSupport;
28 import com.puppycrawl.tools.checkstyle.api.TokenTypes;
29
30 public class MultilineCommentLeadingAsteriskPresenceCheckTest extends AbstractModuleTestSupport {
31
32 @Override
33 public String getPackageLocation() {
34 return "com/puppycrawl/tools/checkstyle/checks/multilinecommentleadingasteriskpresence";
35 }
36
37 @Test
38 public void testGetRequiredTokens() {
39 final MultilineCommentLeadingAsteriskPresenceCheck checkObj =
40 new MultilineCommentLeadingAsteriskPresenceCheck();
41 final int[] expected = {
42 TokenTypes.BLOCK_COMMENT_BEGIN,
43 };
44 assertWithMessage("Required tokens differs from expected")
45 .that(checkObj.getRequiredTokens())
46 .isEqualTo(expected);
47 }
48
49 @Test
50 public void testAcceptableTokens() {
51 final MultilineCommentLeadingAsteriskPresenceCheck checkObj =
52 new MultilineCommentLeadingAsteriskPresenceCheck();
53 final int[] expected = {
54 TokenTypes.BLOCK_COMMENT_BEGIN,
55 };
56 assertWithMessage("Accepted tokens differs from expected")
57 .that(checkObj.getAcceptableTokens())
58 .isEqualTo(expected);
59 }
60
61 @Test
62 public void testInputMultilineComment1() throws Exception {
63 final String[] expected = {
64 "1:1: " + getCheckMessage(MSG_MISSING_ASTERISK, "2, 3"),
65 "12:5: " + getCheckMessage(MSG_MISSING_ASTERISK, "13"),
66 "20:5: " + getCheckMessage(MSG_MISSING_ASTERISK, "21, 22, 23"),
67 "30:5: " + getCheckMessage(MSG_MISSING_ASTERISK, "31, 32, 33, 34"),
68 };
69
70 verifyWithInlineConfigParser(
71 getPath("InputMultilineCommentLeadingAsteriskPresence1.java"),
72 expected);
73 }
74
75 @Test
76 public void testInputMultilineCommentCorrect() throws Exception {
77 final String[] expected = {
78 "1:1: " + getCheckMessage(MSG_MISSING_ASTERISK, "2, 3"),
79 };
80
81 verifyWithInlineConfigParser(
82 getPath("InputMultilineCommentLeadingAsteriskPresenceCorrect.java"),
83 expected);
84 }
85
86 @Test
87 public void testNotMultilineComment() throws Exception {
88 final String[] expected = {
89 "1:1: " + getCheckMessage(MSG_MISSING_ASTERISK, "2, 3"),
90 };
91
92 verifyWithInlineConfigParser(
93 getPath("InputMultilineCommentLeadingAsteriskPresenceJavadoc.java"),
94 expected);
95 }
96
97 @Test
98 public void testMissingAsteriskInBetween() throws Exception {
99 final String[] expected = {
100 "1:1: " + getCheckMessage(MSG_MISSING_ASTERISK, "2, 3"),
101 "12:5: " + getCheckMessage(MSG_MISSING_ASTERISK, "14"),
102 "21:5: " + getCheckMessage(MSG_MISSING_ASTERISK, "23, 24"),
103 "31:5: " + getCheckMessage(MSG_MISSING_ASTERISK, "32, 34"),
104 };
105
106 verifyWithInlineConfigParser(
107 getPath("InputMultilineCommentLeadingAsteriskPresence2.java"),
108 expected);
109 }
110
111 @Test
112 public void testCompactSourceFile() throws Exception {
113 final String[] expected = {
114 "1:1: " + getCheckMessage(MSG_MISSING_ASTERISK, "2, 3"),
115 };
116
117 final String filename =
118 "compact/InputMultilineCommentLeadingAsteriskPresenceCompactSorceFile.java";
119 verifyWithInlineConfigParser(
120 getNonCompilablePath(filename), expected);
121 }
122
123 }