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.SingleLineJavadocCheck.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.TokenTypes;
29  
30  public class SingleLineJavadocCheckTest extends AbstractModuleTestSupport {
31  
32      @Override
33      protected String getPackageLocation() {
34          return "com/puppycrawl/tools/checkstyle/checks/javadoc/singlelinejavadoc";
35      }
36  
37      @Test
38      public void testAcceptableTokens() {
39          final SingleLineJavadocCheck checkObj = new SingleLineJavadocCheck();
40          final int[] expected = {TokenTypes.BLOCK_COMMENT_BEGIN };
41          assertWithMessage("Default acceptable tokens are invalid")
42                  .that(checkObj.getAcceptableTokens())
43                  .isEqualTo(expected);
44      }
45  
46      @Test
47      public void testGetRequiredTokens() {
48          final SingleLineJavadocCheck checkObj = new SingleLineJavadocCheck();
49          final int[] expected = {TokenTypes.BLOCK_COMMENT_BEGIN };
50          assertWithMessage("Default required tokens are invalid")
51                  .that(checkObj.getRequiredTokens())
52                  .isEqualTo(expected);
53      }
54  
55      @Test
56      public void simpleTest() throws Exception {
57          final String[] expected = {
58              "22: " + getCheckMessage(MSG_KEY),
59              "38: " + getCheckMessage(MSG_KEY),
60              "50: " + getCheckMessage(MSG_KEY),
61              "53: " + getCheckMessage(MSG_KEY),
62              "59: " + getCheckMessage(MSG_KEY),
63          };
64          verifyWithInlineConfigParser(
65                  getPath("InputSingleLineJavadoc.java"), expected);
66      }
67  
68      @Test
69      public void testIgnoredTags() throws Exception {
70          final String[] expected = {
71              "14: " + getCheckMessage(MSG_KEY),
72              "44: " + getCheckMessage(MSG_KEY),
73              "47: " + getCheckMessage(MSG_KEY),
74              "50: " + getCheckMessage(MSG_KEY),
75              "56: " + getCheckMessage(MSG_KEY),
76              "59: " + getCheckMessage(MSG_KEY),
77          };
78          verifyWithInlineConfigParser(
79                  getPath("InputSingleLineJavadocIgnoredTags.java"), expected);
80      }
81  
82  }