View Javadoc
1   ///////////////////////////////////////////////////////////////////////////////////////////////
2   // checkstyle: Checks Java source code and other text files for adherence to a set of rules.
3   // Copyright (C) 2001-2024 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.google.common.truth.Truth.assertWithMessage;
23  import static com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocMissingWhitespaceAfterAsteriskCheck.MSG_KEY;
24  
25  import org.junit.jupiter.api.Test;
26  
27  import com.puppycrawl.tools.checkstyle.AbstractModuleTestSupport;
28  import com.puppycrawl.tools.checkstyle.api.JavadocTokenTypes;
29  import com.puppycrawl.tools.checkstyle.utils.CommonUtil;
30  
31  public class JavadocMissingWhitespaceAfterAsteriskCheckTest
32      extends AbstractModuleTestSupport {
33  
34      @Override
35      protected String getPackageLocation() {
36          return "com/puppycrawl/tools/checkstyle/checks/javadoc"
37                  + "/javadocmissingwhitespaceafterasterisk";
38      }
39  
40      @Test
41      public void testGetAcceptableTokens() {
42          final JavadocMissingWhitespaceAfterAsteriskCheck checkObj =
43                  new JavadocMissingWhitespaceAfterAsteriskCheck();
44          final int[] expected = {
45              JavadocTokenTypes.JAVADOC,
46              JavadocTokenTypes.LEADING_ASTERISK,
47          };
48          assertWithMessage("Default tokens are invalid")
49              .that(checkObj.getAcceptableJavadocTokens())
50              .isEqualTo(expected);
51      }
52  
53      @Test
54      public void testGetRequiredJavadocTokens() {
55          final JavadocMissingWhitespaceAfterAsteriskCheck checkObj =
56                  new JavadocMissingWhitespaceAfterAsteriskCheck();
57          final int[] expected = {
58              JavadocTokenTypes.JAVADOC,
59              JavadocTokenTypes.LEADING_ASTERISK,
60          };
61          assertWithMessage("Default required tokens are invalid")
62              .that(checkObj.getRequiredJavadocTokens())
63              .isEqualTo(expected);
64      }
65  
66      @Test
67      public void testValid() throws Exception {
68          final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
69  
70          verifyWithInlineConfigParser(
71                  getPath("InputJavadocMissingWhitespaceAfterAsteriskValid.java"), expected);
72      }
73  
74      @Test
75      public void testValidWithTabCharacter() throws Exception {
76          final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
77  
78          verifyWithInlineConfigParser(
79                  getPath("InputJavadocMissingWhitespaceAfterAsteriskValidWithTab.java"), expected);
80      }
81  
82      @Test
83      public void testInvalid() throws Exception {
84          final String[] expected = {
85              "10:4: " + getCheckMessage(MSG_KEY),
86              "16:7: " + getCheckMessage(MSG_KEY),
87              "21:11: " + getCheckMessage(MSG_KEY),
88              "28:11: " + getCheckMessage(MSG_KEY),
89              "32:13: " + getCheckMessage(MSG_KEY),
90              "38:7: " + getCheckMessage(MSG_KEY),
91              "43:7: " + getCheckMessage(MSG_KEY),
92              "48:7: " + getCheckMessage(MSG_KEY),
93              "53:7: " + getCheckMessage(MSG_KEY),
94              "55:7: " + getCheckMessage(MSG_KEY),
95              "59:8: " + getCheckMessage(MSG_KEY),
96              "62:8: " + getCheckMessage(MSG_KEY),
97              "65:10: " + getCheckMessage(MSG_KEY),
98          };
99          verifyWithInlineConfigParser(
100                 getPath("InputJavadocMissingWhitespaceAfterAsteriskInvalid.java"), expected);
101     }
102 
103 }