1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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_PRECEDED_BLOCK_TAG;
26 import static com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocParagraphCheck.MSG_REDUNDANT_PARAGRAPH;
27 import static com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocParagraphCheck.MSG_TAG_AFTER;
28
29 import org.junit.jupiter.api.Test;
30
31 import com.puppycrawl.tools.checkstyle.AbstractModuleTestSupport;
32 import com.puppycrawl.tools.checkstyle.api.TokenTypes;
33 import com.puppycrawl.tools.checkstyle.utils.CommonUtil;
34
35 public class JavadocParagraphCheckTest extends AbstractModuleTestSupport {
36
37 @Override
38 protected String getPackageLocation() {
39 return "com/puppycrawl/tools/checkstyle/checks/javadoc/javadocparagraph";
40 }
41
42 @Test
43 public void testGetRequiredTokens() {
44 final JavadocParagraphCheck checkObj = new JavadocParagraphCheck();
45 final int[] expected = {TokenTypes.BLOCK_COMMENT_BEGIN};
46 assertWithMessage("Default required tokens are invalid")
47 .that(checkObj.getRequiredTokens())
48 .isEqualTo(expected);
49 }
50
51 @Test
52 public void testCorrect() throws Exception {
53 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
54
55 verifyWithInlineConfigParser(
56 getPath("InputJavadocParagraphCorrect.java"), expected);
57 }
58
59 @Test
60 public void testIncorrect() throws Exception {
61 final String[] expected = {
62 "14:4: " + getCheckMessage(MSG_LINE_BEFORE),
63 "15:19: " + getCheckMessage(MSG_LINE_BEFORE),
64 "22:21: " + getCheckMessage(MSG_LINE_BEFORE),
65 "24:8: " + getCheckMessage(MSG_MISPLACED_TAG),
66 "34:13: " + getCheckMessage(MSG_LINE_BEFORE),
67 "36:8: " + getCheckMessage(MSG_MISPLACED_TAG),
68 "47:8: " + getCheckMessage(MSG_REDUNDANT_PARAGRAPH),
69 "47:24: " + getCheckMessage(MSG_LINE_BEFORE),
70 "48:8: " + getCheckMessage(MSG_LINE_BEFORE),
71 "49:8: " + getCheckMessage(MSG_LINE_BEFORE),
72 "49:11: " + getCheckMessage(MSG_LINE_BEFORE),
73 "50:8: " + getCheckMessage(MSG_MISPLACED_TAG),
74 "50:8: " + getCheckMessage(MSG_LINE_BEFORE),
75 "50:29: " + getCheckMessage(MSG_MISPLACED_TAG),
76 "50:29: " + getCheckMessage(MSG_LINE_BEFORE),
77 "62:25: " + getCheckMessage(MSG_LINE_BEFORE),
78 "69:12: " + getCheckMessage(MSG_REDUNDANT_PARAGRAPH),
79 "75:29: " + getCheckMessage(MSG_LINE_BEFORE),
80 "86:12: " + getCheckMessage(MSG_REDUNDANT_PARAGRAPH),
81 "87:11: " + getCheckMessage(MSG_TAG_AFTER),
82 "97:27: " + getCheckMessage(MSG_LINE_BEFORE),
83 "99:13: " + getCheckMessage(MSG_MISPLACED_TAG),
84 "109:11: " + getCheckMessage(MSG_TAG_AFTER),
85 "110:11: " + getCheckMessage(MSG_TAG_AFTER),
86 };
87 verifyWithInlineConfigParser(
88 getPath("InputJavadocParagraphIncorrect.java"), expected);
89 }
90
91 @Test
92 public void testIncorrect2() throws Exception {
93 final String[] expected = {
94 "14:4: " + getCheckMessage(MSG_PRECEDED_BLOCK_TAG, "h1"),
95 "22:7: " + getCheckMessage(MSG_PRECEDED_BLOCK_TAG, "ul"),
96 "37:8: " + getCheckMessage(MSG_PRECEDED_BLOCK_TAG, "table"),
97 "49:8: " + getCheckMessage(MSG_MISPLACED_TAG),
98 "51:8: " + getCheckMessage(MSG_MISPLACED_TAG),
99 "51:8: " + getCheckMessage(MSG_PRECEDED_BLOCK_TAG, "ol"),
100 "64:63: " + getCheckMessage(MSG_LINE_BEFORE),
101 "65:7: " + getCheckMessage(MSG_TAG_AFTER),
102 };
103 verifyWithInlineConfigParser(
104 getPath("InputJavadocParagraphIncorrect4.java"), expected);
105 }
106
107 @Test
108 public void testAllowNewlineParagraph() throws Exception {
109 final String[] expected = {
110 "16:4: " + getCheckMessage(MSG_MISPLACED_TAG),
111 "16:4: " + getCheckMessage(MSG_LINE_BEFORE),
112 "17:19: " + getCheckMessage(MSG_MISPLACED_TAG),
113 "17:19: " + getCheckMessage(MSG_LINE_BEFORE),
114 "28:21: " + getCheckMessage(MSG_MISPLACED_TAG),
115 "28:21: " + getCheckMessage(MSG_LINE_BEFORE),
116 "30:8: " + getCheckMessage(MSG_MISPLACED_TAG),
117 "39:13: " + getCheckMessage(MSG_LINE_BEFORE),
118 "41:8: " + getCheckMessage(MSG_MISPLACED_TAG),
119 "56:8: " + getCheckMessage(MSG_REDUNDANT_PARAGRAPH),
120 "56:24: " + getCheckMessage(MSG_MISPLACED_TAG),
121 "56:24: " + getCheckMessage(MSG_LINE_BEFORE),
122 "57:8: " + getCheckMessage(MSG_MISPLACED_TAG),
123 "57:8: " + getCheckMessage(MSG_LINE_BEFORE),
124 "58:8: " + getCheckMessage(MSG_LINE_BEFORE),
125 "58:11: " + getCheckMessage(MSG_MISPLACED_TAG),
126 "58:11: " + getCheckMessage(MSG_LINE_BEFORE),
127 "59:8: " + getCheckMessage(MSG_MISPLACED_TAG),
128 "59:8: " + getCheckMessage(MSG_LINE_BEFORE),
129 "59:29: " + getCheckMessage(MSG_MISPLACED_TAG),
130 "59:29: " + getCheckMessage(MSG_LINE_BEFORE),
131 "75:25: " + getCheckMessage(MSG_MISPLACED_TAG),
132 "75:25: " + getCheckMessage(MSG_LINE_BEFORE),
133 "86:12: " + getCheckMessage(MSG_MISPLACED_TAG),
134 "86:12: " + getCheckMessage(MSG_REDUNDANT_PARAGRAPH),
135 "89:12: " + getCheckMessage(MSG_MISPLACED_TAG),
136 "91:12: " + getCheckMessage(MSG_MISPLACED_TAG),
137 "92:29: " + getCheckMessage(MSG_MISPLACED_TAG),
138 "92:29: " + getCheckMessage(MSG_LINE_BEFORE),
139 "103:12: " + getCheckMessage(MSG_MISPLACED_TAG),
140 "103:12: " + getCheckMessage(MSG_LINE_BEFORE),
141 "103:31: " + getCheckMessage(MSG_MISPLACED_TAG),
142 "103:31: " + getCheckMessage(MSG_LINE_BEFORE),
143 };
144 verifyWithInlineConfigParser(
145 getPath("InputJavadocParagraphIncorrect2.java"), expected);
146 }
147
148 @Test
149 public void testAllowNewlineParagraph2() throws Exception {
150 final String[] expected = {
151 "16:12: " + getCheckMessage(MSG_REDUNDANT_PARAGRAPH),
152 "17:11: " + getCheckMessage(MSG_TAG_AFTER),
153 "30:27: " + getCheckMessage(MSG_MISPLACED_TAG),
154 "30:27: " + getCheckMessage(MSG_LINE_BEFORE),
155 "32:13: " + getCheckMessage(MSG_MISPLACED_TAG),
156 "42:11: " + getCheckMessage(MSG_TAG_AFTER),
157 "43:11: " + getCheckMessage(MSG_TAG_AFTER),
158 };
159 verifyWithInlineConfigParser(
160 getPath("InputJavadocParagraphIncorrect3.java"), expected);
161 }
162
163 @Test
164 public void testAllowNewlineParagraph3() throws Exception {
165 final String[] expected = {
166 "42:8: " + getCheckMessage(MSG_MISPLACED_TAG),
167 "46:8: " + getCheckMessage(MSG_MISPLACED_TAG),
168 "46:8: " + getCheckMessage(MSG_PRECEDED_BLOCK_TAG, "h1"),
169 "73:8: " + getCheckMessage(MSG_MISPLACED_TAG),
170 "73:8: " + getCheckMessage(MSG_PRECEDED_BLOCK_TAG, "ul"),
171 };
172 verifyWithInlineConfigParser(
173 getPath("InputJavadocParagraphIncorrect5.java"), expected);
174 }
175
176 @Test
177 public void testJavadocParagraph() throws Exception {
178 final String[] expected = {
179 "19:4: " + getCheckMessage(MSG_LINE_BEFORE),
180 "28:7: " + getCheckMessage(MSG_REDUNDANT_PARAGRAPH),
181 "31:7: " + getCheckMessage(MSG_LINE_BEFORE),
182 "50:7: " + getCheckMessage(MSG_PRECEDED_BLOCK_TAG, "ul"),
183 "76:8: " + getCheckMessage(MSG_PRECEDED_BLOCK_TAG, "table"),
184 "87:8: " + getCheckMessage(MSG_PRECEDED_BLOCK_TAG, "pre"),
185 };
186
187 verifyWithInlineConfigParser(
188 getPath("InputJavadocParagraphCheck1.java"), expected);
189 }
190
191 @Test
192 public void testJavadocParagraphOpenClosedTag() throws Exception {
193 final String[] expected = {
194 "14:4: " + getCheckMessage(MSG_MISPLACED_TAG),
195 "21:7: " + getCheckMessage(MSG_LINE_BEFORE),
196 "28:20: " + getCheckMessage(MSG_LINE_BEFORE),
197 "29:20: " + getCheckMessage(MSG_LINE_BEFORE),
198 "35:8: " + getCheckMessage(MSG_REDUNDANT_PARAGRAPH),
199 "36:6: " + getCheckMessage(MSG_TAG_AFTER),
200 "38:6: " + getCheckMessage(MSG_TAG_AFTER),
201 "58:7: " + getCheckMessage(MSG_PRECEDED_BLOCK_TAG, "ul"),
202 "73:7: " + getCheckMessage(MSG_PRECEDED_BLOCK_TAG, "h1"),
203 "85:7: " + getCheckMessage(MSG_PRECEDED_BLOCK_TAG, "h1"),
204 };
205
206 verifyWithInlineConfigParser(
207 getPath("InputJavadocParagraphIncorrectOpenClosedTag.java"), expected);
208 }
209
210 @Test
211 public void testJavadocParagraphOpenClosedTag2() throws Exception {
212 final String[] expected = {
213 "14:4: " + getCheckMessage(MSG_MISPLACED_TAG),
214 "21:7: " + getCheckMessage(MSG_LINE_BEFORE),
215 "30:20: " + getCheckMessage(MSG_MISPLACED_TAG),
216 "30:20: " + getCheckMessage(MSG_LINE_BEFORE),
217 "31:20: " + getCheckMessage(MSG_LINE_BEFORE),
218 "37:8: " + getCheckMessage(MSG_REDUNDANT_PARAGRAPH),
219 "38:6: " + getCheckMessage(MSG_TAG_AFTER),
220 "40:6: " + getCheckMessage(MSG_TAG_AFTER),
221 "50:7: " + getCheckMessage(MSG_MISPLACED_TAG),
222 "63:7: " + getCheckMessage(MSG_MISPLACED_TAG),
223 "63:7: " + getCheckMessage(MSG_PRECEDED_BLOCK_TAG, "ul"),
224 "78:7: " + getCheckMessage(MSG_PRECEDED_BLOCK_TAG, "h1"),
225 "87:7: " + getCheckMessage(MSG_MISPLACED_TAG),
226 "91:7: " + getCheckMessage(MSG_MISPLACED_TAG),
227 "91:7: " + getCheckMessage(MSG_PRECEDED_BLOCK_TAG, "h1"),
228 };
229
230 verifyWithInlineConfigParser(
231 getPath("InputJavadocParagraphIncorrectOpenClosedTag2.java"), expected);
232 }
233
234 @Test
235 public void testJavadocParagraphOpenClosedTag3() throws Exception {
236 final String[] expected = {
237 "15:7: " + getCheckMessage(MSG_MISPLACED_TAG),
238 "23:7: " + getCheckMessage(MSG_MISPLACED_TAG),
239 "31:7: " + getCheckMessage(MSG_MISPLACED_TAG),
240 };
241
242 verifyWithInlineConfigParser(
243 getPath("InputJavadocParagraphIncorrectOpenClosedTag3.java"), expected);
244 }
245
246 @Test
247 public void testIncorrect3() throws Exception {
248 final String[] expected = {
249 "15:7: " + getCheckMessage(MSG_MISPLACED_TAG),
250 "23:7: " + getCheckMessage(MSG_MISPLACED_TAG),
251 "31:7: " + getCheckMessage(MSG_MISPLACED_TAG),
252 };
253
254 verifyWithInlineConfigParser(
255 getPath("InputJavadocParagraphIncorrect6.java"), expected);
256 }
257
258 @Test
259 public void testJavadocParagraphNested() throws Exception {
260 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
261
262 verifyWithInlineConfigParser(
263 getPath("InputJavadocParagraphNested.java"), expected);
264 }
265 }