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.JavadocTagContinuationIndentationCheck.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  import com.puppycrawl.tools.checkstyle.utils.CommonUtil;
30  
31  public class JavadocTagContinuationIndentationCheckTest
32          extends AbstractModuleTestSupport {
33  
34      @Override
35      protected String getPackageLocation() {
36          return "com/puppycrawl/tools/checkstyle/checks/javadoc/javadoctagcontinuationindentation";
37      }
38  
39      @Test
40      public void testGetRequiredTokens() {
41          final JavadocTagContinuationIndentationCheck checkObj =
42              new JavadocTagContinuationIndentationCheck();
43          final int[] expected = {TokenTypes.BLOCK_COMMENT_BEGIN };
44          assertWithMessage("Default required tokens are invalid")
45              .that(checkObj.getRequiredTokens())
46              .isEqualTo(expected);
47      }
48  
49      @Test
50      public void testFp() throws Exception {
51          final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
52          verifyWithInlineConfigParser(
53                  getPath("InputJavadocTagContinuationIndentationGuavaFalsePositive.java"),
54                 expected);
55      }
56  
57      @Test
58      public void testCheck() throws Exception {
59          final String[] expected = {
60              "55: " + getCheckMessage(MSG_KEY, 4),
61              "117: " + getCheckMessage(MSG_KEY, 4),
62              "120: " + getCheckMessage(MSG_KEY, 4),
63              "211: " + getCheckMessage(MSG_KEY, 4),
64              "214: " + getCheckMessage(MSG_KEY, 4),
65              "229: " + getCheckMessage(MSG_KEY, 4),
66              "231: " + getCheckMessage(MSG_KEY, 4),
67              "293: " + getCheckMessage(MSG_KEY, 4),
68              "296: " + getCheckMessage(MSG_KEY, 4),
69              "298: " + getCheckMessage(MSG_KEY, 4),
70              "318: " + getCheckMessage(MSG_KEY, 4),
71              "330: " + getCheckMessage(MSG_KEY, 4),
72              "332: " + getCheckMessage(MSG_KEY, 4),
73              "350: " + getCheckMessage(MSG_KEY, 4),
74          };
75          verifyWithInlineConfigParser(
76                  getPath("InputJavadocTagContinuationIndentation.java"),
77                  expected);
78      }
79  
80      @Test
81      public void testCheckWithOffset3() throws Exception {
82          final String[] expected = {
83              "15: " + getCheckMessage(MSG_KEY, 3),
84              "27: " + getCheckMessage(MSG_KEY, 3),
85          };
86          verifyWithInlineConfigParser(
87                  getPath("InputJavadocTagContinuationIndentationOffset3.java"),
88                  expected);
89      }
90  
91      @Test
92      public void testCheckWithDescription() throws Exception {
93          final String[] expected = {
94              "16: " + getCheckMessage(MSG_KEY, 4),
95              "17: " + getCheckMessage(MSG_KEY, 4),
96              "18: " + getCheckMessage(MSG_KEY, 4),
97              "47: " + getCheckMessage(MSG_KEY, 4),
98              "49: " + getCheckMessage(MSG_KEY, 4),
99              "50: " + getCheckMessage(MSG_KEY, 4),
100         };
101         verifyWithInlineConfigParser(
102                 getPath("InputJavadocTagContinuationIndentationDescription.java"),
103                 expected);
104     }
105 
106     @Test
107     public void testBlockTag() throws Exception {
108         final String[] expected = {
109             "21: " + getCheckMessage(MSG_KEY, 4),
110             "32: " + getCheckMessage(MSG_KEY, 4),
111             "42: " + getCheckMessage(MSG_KEY, 4),
112             "62: " + getCheckMessage(MSG_KEY, 4),
113             "64: " + getCheckMessage(MSG_KEY, 4),
114             "74: " + getCheckMessage(MSG_KEY, 4),
115             "75: " + getCheckMessage(MSG_KEY, 4),
116             "76: " + getCheckMessage(MSG_KEY, 4),
117             "86: " + getCheckMessage(MSG_KEY, 4),
118             "87: " + getCheckMessage(MSG_KEY, 4),
119             "88: " + getCheckMessage(MSG_KEY, 4),
120             "89: " + getCheckMessage(MSG_KEY, 4),
121             "90: " + getCheckMessage(MSG_KEY, 4),
122             "91: " + getCheckMessage(MSG_KEY, 4),
123             "92: " + getCheckMessage(MSG_KEY, 4),
124             "93: " + getCheckMessage(MSG_KEY, 4),
125             "94: " + getCheckMessage(MSG_KEY, 4),
126             "95: " + getCheckMessage(MSG_KEY, 4),
127             "96: " + getCheckMessage(MSG_KEY, 4),
128             "97: " + getCheckMessage(MSG_KEY, 4),
129             "98: " + getCheckMessage(MSG_KEY, 4),
130             "99: " + getCheckMessage(MSG_KEY, 4),
131             "104: " + getCheckMessage(MSG_KEY, 4),
132             "105: " + getCheckMessage(MSG_KEY, 4),
133         };
134         verifyWithInlineConfigParser(
135                 getPath("InputJavadocTagContinuationIndentationBlockTag.java"),
136                 expected);
137     }
138 
139     @Test
140     public void testContinuationIndentation() throws Exception {
141         final String[] expected = {
142             "23: " + getCheckMessage(MSG_KEY, 4),
143         };
144         verifyWithInlineConfigParser(
145                 getPath("InputJavadocTagContinuationIndentation1.java"),
146                 expected);
147     }
148 
149     @Test
150     public void testJavadocTagContinuationIndentationCheck1() throws Exception {
151         final String[] expected = {
152             "16: " + getCheckMessage(MSG_KEY, 4),
153         };
154         verifyWithInlineConfigParser(
155                 getPath("InputJavadocTagContinuationIndentationCheck1.java"),
156                 expected);
157     }
158 }