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.JavadocParagraphCheck.MSG_LINE_BEFORE;
24  import static com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocParagraphCheck.MSG_MISPLACED_TAG;
25  import static com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocParagraphCheck.MSG_REDUNDANT_PARAGRAPH;
26  import static com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocParagraphCheck.MSG_TAG_AFTER;
27  
28  import org.junit.jupiter.api.Test;
29  
30  import com.puppycrawl.tools.checkstyle.AbstractModuleTestSupport;
31  import com.puppycrawl.tools.checkstyle.api.TokenTypes;
32  import com.puppycrawl.tools.checkstyle.utils.CommonUtil;
33  
34  public class JavadocParagraphCheckTest extends AbstractModuleTestSupport {
35  
36      @Override
37      protected String getPackageLocation() {
38          return "com/puppycrawl/tools/checkstyle/checks/javadoc/javadocparagraph";
39      }
40  
41      @Test
42      public void testGetRequiredTokens() {
43          final JavadocParagraphCheck checkObj = new JavadocParagraphCheck();
44          final int[] expected = {TokenTypes.BLOCK_COMMENT_BEGIN};
45          assertWithMessage("Default required tokens are invalid")
46              .that(checkObj.getRequiredTokens())
47              .isEqualTo(expected);
48      }
49  
50      @Test
51      public void testCorrect() throws Exception {
52          final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
53  
54          verifyWithInlineConfigParser(
55                  getPath("InputJavadocParagraphCorrect.java"), expected);
56      }
57  
58      @Test
59      public void testIncorrect() throws Exception {
60          final String[] expected = {
61              "14: " + getCheckMessage(MSG_LINE_BEFORE),
62              "15: " + getCheckMessage(MSG_LINE_BEFORE),
63              "23: " + getCheckMessage(MSG_LINE_BEFORE),
64              "25: " + getCheckMessage(MSG_MISPLACED_TAG),
65              "33: " + getCheckMessage(MSG_LINE_BEFORE),
66              "35: " + getCheckMessage(MSG_MISPLACED_TAG),
67              "46: " + getCheckMessage(MSG_LINE_BEFORE),
68              "46: " + getCheckMessage(MSG_REDUNDANT_PARAGRAPH),
69              "47: " + getCheckMessage(MSG_LINE_BEFORE),
70              "48: " + getCheckMessage(MSG_LINE_BEFORE),
71              "49: " + getCheckMessage(MSG_MISPLACED_TAG),
72              "49: " + getCheckMessage(MSG_LINE_BEFORE),
73              "58: " + getCheckMessage(MSG_LINE_BEFORE),
74              "65: " + getCheckMessage(MSG_REDUNDANT_PARAGRAPH),
75              "68: " + getCheckMessage(MSG_MISPLACED_TAG),
76              "70: " + getCheckMessage(MSG_LINE_BEFORE),
77              "71: " + getCheckMessage(MSG_LINE_BEFORE),
78              "84: " + getCheckMessage(MSG_REDUNDANT_PARAGRAPH),
79              "85: " + getCheckMessage(MSG_TAG_AFTER),
80              "95: " + getCheckMessage(MSG_LINE_BEFORE),
81              "97: " + getCheckMessage(MSG_MISPLACED_TAG),
82              "100: " + getCheckMessage(MSG_MISPLACED_TAG),
83              "100: " + getCheckMessage(MSG_LINE_BEFORE),
84              "110: " + getCheckMessage(MSG_TAG_AFTER),
85              "111: " + getCheckMessage(MSG_TAG_AFTER),
86          };
87          verifyWithInlineConfigParser(
88                  getPath("InputJavadocParagraphIncorrect.java"), expected);
89      }
90  
91      @Test
92      public void testAllowNewlineParagraph() throws Exception {
93          final String[] expected = {
94              "16: " + getCheckMessage(MSG_MISPLACED_TAG),
95              "16: " + getCheckMessage(MSG_LINE_BEFORE),
96              "17: " + getCheckMessage(MSG_MISPLACED_TAG),
97              "17: " + getCheckMessage(MSG_LINE_BEFORE),
98              "28: " + getCheckMessage(MSG_MISPLACED_TAG),
99              "28: " + getCheckMessage(MSG_LINE_BEFORE),
100             "30: " + getCheckMessage(MSG_MISPLACED_TAG),
101             "39: " + getCheckMessage(MSG_LINE_BEFORE),
102             "41: " + getCheckMessage(MSG_MISPLACED_TAG),
103             "56: " + getCheckMessage(MSG_MISPLACED_TAG),
104             "56: " + getCheckMessage(MSG_LINE_BEFORE),
105             "56: " + getCheckMessage(MSG_REDUNDANT_PARAGRAPH),
106             "57: " + getCheckMessage(MSG_MISPLACED_TAG),
107             "57: " + getCheckMessage(MSG_LINE_BEFORE),
108             "58: " + getCheckMessage(MSG_MISPLACED_TAG),
109             "58: " + getCheckMessage(MSG_LINE_BEFORE),
110             "59: " + getCheckMessage(MSG_MISPLACED_TAG),
111             "59: " + getCheckMessage(MSG_LINE_BEFORE),
112             "72: " + getCheckMessage(MSG_MISPLACED_TAG),
113             "72: " + getCheckMessage(MSG_LINE_BEFORE),
114             "83: " + getCheckMessage(MSG_MISPLACED_TAG),
115             "83: " + getCheckMessage(MSG_REDUNDANT_PARAGRAPH),
116             "86: " + getCheckMessage(MSG_MISPLACED_TAG),
117             "88: " + getCheckMessage(MSG_MISPLACED_TAG),
118             "88: " + getCheckMessage(MSG_LINE_BEFORE),
119             "89: " + getCheckMessage(MSG_MISPLACED_TAG),
120             "89: " + getCheckMessage(MSG_LINE_BEFORE),
121             "106: " + getCheckMessage(MSG_REDUNDANT_PARAGRAPH),
122             "107: " + getCheckMessage(MSG_TAG_AFTER),
123             "120: " + getCheckMessage(MSG_MISPLACED_TAG),
124             "120: " + getCheckMessage(MSG_LINE_BEFORE),
125             "122: " + getCheckMessage(MSG_MISPLACED_TAG),
126             "125: " + getCheckMessage(MSG_MISPLACED_TAG),
127             "125: " + getCheckMessage(MSG_LINE_BEFORE),
128             "135: " + getCheckMessage(MSG_TAG_AFTER),
129             "136: " + getCheckMessage(MSG_TAG_AFTER),
130         };
131         verifyWithInlineConfigParser(
132                 getPath("InputJavadocParagraphIncorrect2.java"), expected);
133     }
134 
135     @Test
136     public void testJavadocParagraph() throws Exception {
137         final String[] expected = {
138             "19: " + getCheckMessage(MSG_LINE_BEFORE),
139             "30: " + getCheckMessage(MSG_LINE_BEFORE),
140         };
141 
142         verifyWithInlineConfigParser(
143                 getPath("InputJavadocParagraphCheck1.java"), expected);
144     }
145 }