View Javadoc
1   ///////////////////////////////////////////////////////////////////////////////////////////////
2   // checkstyle: Checks Java source code and other text files for adherence to a set of rules.
3   // Copyright (C) 2001-2026 the original author or authors.
4   //
5   // This library is free software; you can redistribute it and/or
6   // modify it under the terms of the GNU Lesser General Public
7   // License as published by the Free Software Foundation; either
8   // version 2.1 of the License, or (at your option) any later version.
9   //
10  // This library is distributed in the hope that it will be useful,
11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  // Lesser General Public License for more details.
14  //
15  // You should have received a copy of the GNU Lesser General Public
16  // License along with this library; if not, write to the Free Software
17  // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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 }