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.javadoc;
21  
22  import static com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocLeadingAsteriskAlignCheck.MSG_KEY;
23  
24  import org.junit.jupiter.api.Test;
25  
26  import com.puppycrawl.tools.checkstyle.AbstractModuleTestSupport;
27  import com.puppycrawl.tools.checkstyle.utils.CommonUtil;
28  
29  public class JavadocLeadingAsteriskAlignCheckTest extends AbstractModuleTestSupport {
30  
31      @Override
32      public String getPackageLocation() {
33          return "com/puppycrawl/tools/checkstyle/checks/javadoc/javadocleadingasteriskalign";
34      }
35  
36      @Test
37      public void testCorrectJavadoc() throws Exception {
38          final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
39  
40          final String filePath = getPath("InputJavadocLeadingAsteriskAlignCorrect.java");
41          verifyWithInlineConfigParser(filePath, expected);
42      }
43  
44      @Test
45      public void testIncorrectJavadoc() throws Exception {
46          final String[] expected = {
47              "13:1: " + getCheckMessage(JavadocLeadingAsteriskAlignCheck.class, MSG_KEY, 1, 2),
48              "19:5: " + getCheckMessage(JavadocLeadingAsteriskAlignCheck.class, MSG_KEY, 5, 4),
49              "26:3: " + getCheckMessage(JavadocLeadingAsteriskAlignCheck.class, MSG_KEY, 3, 4),
50              "33:5: " + getCheckMessage(JavadocLeadingAsteriskAlignCheck.class, MSG_KEY, 5, 4),
51              "38:3: " + getCheckMessage(JavadocLeadingAsteriskAlignCheck.class, MSG_KEY, 3, 4),
52              "43:7: " + getCheckMessage(JavadocLeadingAsteriskAlignCheck.class, MSG_KEY, 7, 4),
53              "49:1: " + getCheckMessage(JavadocLeadingAsteriskAlignCheck.class, MSG_KEY, 1, 4),
54              "56:7: " + getCheckMessage(JavadocLeadingAsteriskAlignCheck.class, MSG_KEY, 7, 4),
55              "62:1: " + getCheckMessage(JavadocLeadingAsteriskAlignCheck.class, MSG_KEY, 1, 4),
56              "68:7: " + getCheckMessage(JavadocLeadingAsteriskAlignCheck.class, MSG_KEY, 7, 4),
57              "69:5: " + getCheckMessage(JavadocLeadingAsteriskAlignCheck.class, MSG_KEY, 5, 4),
58              "74:9: " + getCheckMessage(JavadocLeadingAsteriskAlignCheck.class, MSG_KEY, 9, 6),
59              "80:8: " + getCheckMessage(JavadocLeadingAsteriskAlignCheck.class, MSG_KEY, 8, 6),
60              "90:4: " + getCheckMessage(JavadocLeadingAsteriskAlignCheck.class, MSG_KEY, 4, 6),
61              "96:7: " + getCheckMessage(JavadocLeadingAsteriskAlignCheck.class, MSG_KEY, 7, 6),
62          };
63  
64          final String filePath = getPath("InputJavadocLeadingAsteriskAlignIncorrect.java");
65          verifyWithInlineConfigParser(filePath, expected);
66      }
67  
68      @Test
69      public void testTabs() throws Exception {
70          final String[] expected = {
71              "50:5: " + getCheckMessage(JavadocLeadingAsteriskAlignCheck.class, MSG_KEY, 5, 4),
72              "62:5: " + getCheckMessage(JavadocLeadingAsteriskAlignCheck.class, MSG_KEY, 5, 6),
73              "63:7: " + getCheckMessage(JavadocLeadingAsteriskAlignCheck.class, MSG_KEY, 7, 6),
74              "74:7: " + getCheckMessage(JavadocLeadingAsteriskAlignCheck.class, MSG_KEY, 7, 6),
75              "75:5: " + getCheckMessage(JavadocLeadingAsteriskAlignCheck.class, MSG_KEY, 5, 6),
76          };
77  
78          final String filePath = getPath("InputJavadocLeadingAsteriskAlignTabs.java");
79          verifyWithInlineConfigParser(filePath, expected);
80      }
81  
82      @Test
83      public void testMultipleLeadingAsterisks() throws Exception {
84          final String[] expected = {
85              "20:5: " + getCheckMessage(JavadocLeadingAsteriskAlignCheck.class, MSG_KEY, 5, 4),
86          };
87  
88          final String filePath = getPath("InputJavadocLeadingAsteriskAlignMultipleAsterisks.java");
89          verifyWithInlineConfigParser(filePath, expected);
90      }
91  
92      @Test
93      public void testLeadingAsteriskOnOpeningLine() throws Exception {
94          final String[] expected = {
95              "18:6: " + getCheckMessage(JavadocLeadingAsteriskAlignCheck.class, MSG_KEY, 6, 11),
96              "19:6: " + getCheckMessage(JavadocLeadingAsteriskAlignCheck.class, MSG_KEY, 6, 11),
97              "20:6: " + getCheckMessage(JavadocLeadingAsteriskAlignCheck.class, MSG_KEY, 6, 11),
98          };
99  
100         final String filePath = getPath("InputJavadocLeadingAsteriskAlignOpeningLine.java");
101         verifyWithInlineConfigParser(filePath, expected);
102     }
103 
104 }