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.InvalidJavadocPositionCheck.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 InvalidJavadocPositionCheckTest extends AbstractModuleTestSupport {
31  
32      @Override
33      protected String getPackageLocation() {
34          return "com/puppycrawl/tools/checkstyle/checks/javadoc/invalidjavadocposition";
35      }
36  
37      @Test
38      public void testGetAcceptableTokens() {
39          final int[] expected = {
40              TokenTypes.BLOCK_COMMENT_BEGIN,
41          };
42          final InvalidJavadocPositionCheck check = new InvalidJavadocPositionCheck();
43          final int[] actual = check.getAcceptableTokens();
44  
45          assertWithMessage("Acceptable tokens differs from expected")
46              .that(actual)
47              .isEqualTo(expected);
48      }
49  
50      @Test
51      public void testGetRequiredTokens() {
52          final int[] expected = {
53              TokenTypes.BLOCK_COMMENT_BEGIN,
54          };
55          final InvalidJavadocPositionCheck check = new InvalidJavadocPositionCheck();
56          final int[] actual = check.getRequiredTokens();
57  
58          assertWithMessage("Required tokens differ from expected")
59              .that(actual)
60              .isEqualTo(expected);
61      }
62  
63      @Test
64      public void testDefault() throws Exception {
65          final String[] expected = {
66              "7:9: " + getCheckMessage(MSG_KEY),
67              "10:1: " + getCheckMessage(MSG_KEY),
68              "13:1: " + getCheckMessage(MSG_KEY),
69              "16:5: " + getCheckMessage(MSG_KEY),
70              "21:5: " + getCheckMessage(MSG_KEY),
71              "24:5: " + getCheckMessage(MSG_KEY),
72              "34:9: " + getCheckMessage(MSG_KEY),
73              "35:17: " + getCheckMessage(MSG_KEY),
74              "36:17: " + getCheckMessage(MSG_KEY),
75              "46:10: " + getCheckMessage(MSG_KEY),
76              "47:19: " + getCheckMessage(MSG_KEY),
77              "48:19: " + getCheckMessage(MSG_KEY),
78              "49:21: " + getCheckMessage(MSG_KEY),
79              "50:23: " + getCheckMessage(MSG_KEY),
80              "51:23: " + getCheckMessage(MSG_KEY),
81              "54:1: " + getCheckMessage(MSG_KEY),
82              "59:7: " + getCheckMessage(MSG_KEY),
83              "60:36: " + getCheckMessage(MSG_KEY),
84              "63:9: " + getCheckMessage(MSG_KEY),
85              "64:9: " + getCheckMessage(MSG_KEY),
86              "65:9: " + getCheckMessage(MSG_KEY),
87              "73:6: " + getCheckMessage(MSG_KEY),
88              "76:24: " + getCheckMessage(MSG_KEY),
89              "79:43: " + getCheckMessage(MSG_KEY),
90              "82:69: " + getCheckMessage(MSG_KEY),
91              "94:1: " + getCheckMessage(MSG_KEY),
92          };
93          verifyWithInlineConfigParser(
94                  getPath("InputInvalidJavadocPosition.java"), expected);
95      }
96  
97      @Test
98      public void testPackageInfo() throws Exception {
99          final String[] expected = {
100             "7:1: " + getCheckMessage(MSG_KEY),
101         };
102         verifyWithInlineConfigParser(
103                 getPath("package-info.java"), expected);
104     }
105 
106     @Test
107     public void testPackageInfoComment() throws Exception {
108         final String[] expected = {
109             "7:1: " + getCheckMessage(MSG_KEY),
110         };
111         verifyWithInlineConfigParser(
112                 getPath("comment/package-info.java"), expected);
113     }
114 
115 }