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.puppycrawl.tools.checkstyle.checks.javadoc.AbstractJavadocCheck.MSG_KEY_UNCLOSED_HTML_TAG;
23 import static com.puppycrawl.tools.checkstyle.checks.javadoc.WriteTagCheck.MSG_MISSING_TAG;
24 import static com.puppycrawl.tools.checkstyle.checks.javadoc.WriteTagCheck.MSG_TAG_FORMAT;
25
26 import org.junit.jupiter.api.Test;
27
28 import com.puppycrawl.tools.checkstyle.AbstractModuleTestSupport;
29 import com.puppycrawl.tools.checkstyle.utils.CommonUtil;
30
31
32
33
34 public class WriteTagCheckTest extends AbstractModuleTestSupport {
35
36 @Override
37 public String getPackageLocation() {
38 return "com/puppycrawl/tools/checkstyle/checks/javadoc/writetag";
39 }
40
41 @Test
42 public void testDefaultSettings() throws Exception {
43 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
44 verifyWithInlineConfigParser(getPath("InputWriteTagDefault.java"), expected);
45 }
46
47 @Test
48 public void testTag() throws Exception {
49 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
50 verifyWithInlineConfigParserTwice(getPath("InputWriteTag.java"), expected);
51 }
52
53 @Test
54 public void testMissingFormat() throws Exception {
55 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
56 verifyWithInlineConfigParserTwice(
57 getPath("InputWriteTagMissingFormat.java"), expected);
58 }
59
60 @Test
61 public void testTagIncomplete() throws Exception {
62 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
63 verifyWithInlineConfigParserTwice(
64 getPath("InputWriteTagIncomplete.java"), expected);
65 }
66
67 @Test
68 public void testDoubleTag() throws Exception {
69 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
70 verifyWithInlineConfigParserTwice(
71 getPath("InputWriteTagDoubleTag.java"), expected);
72 }
73
74 @Test
75 public void testEmptyTag() throws Exception {
76 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
77 verifyWithInlineConfigParserTwice(
78 getPath("InputWriteTagEmptyTag.java"), expected);
79 }
80
81 @Test
82 public void testMissingTag() throws Exception {
83 final String[] expected = {
84 "20:1: " + getCheckMessage(MSG_MISSING_TAG, "@missingtag"),
85 };
86 verifyWithInlineConfigParserTwice(
87 getPath("InputWriteTagMissingTag.java"), expected);
88 }
89
90 @Test
91 public void testMissingTagOnMethod() throws Exception {
92 final String[] expected = {
93 "16:5: " + getCheckMessage(MSG_MISSING_TAG, "@since"),
94 };
95 verifyWithInlineConfigParserTwice(
96 getPath("InputWriteTagMissingTagMethod.java"), expected);
97 }
98
99 @Test
100 public void testCompactSourceFile() throws Exception {
101 final String[] expected = {
102 "20:1: " + getCheckMessage(MSG_MISSING_TAG, "@since"),
103 };
104 verifyWithInlineConfigParserTwice(
105 getNonCompilablePath("compact/InputWriteTagCheckNonCompactSourceFile.java"),
106 expected);
107 }
108
109 @Test
110 public void testDefault() throws Exception {
111 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
112 verifyWithInlineConfigParserTwice(
113 getNonCompilablePath("compact/InputWriteTagCheckDefaultTokens.java"), expected);
114 }
115
116 @Test
117 public void testTagContent() throws Exception {
118 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
119 verifyWithInlineConfigParserTwice(
120 getNonCompilablePath("compact/InputWriteTagCheckExactTagContent.java"), expected);
121 }
122
123 @Test
124 public void testInterface() throws Exception {
125 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
126 verifyWithInlineConfigParserTwice(
127 getPath("InputWriteTagInterface.java"), expected
128 );
129 }
130
131 @Test
132 public void testEnum() throws Exception {
133 final String[] expected = {
134 "17:5: " + getCheckMessage(MSG_MISSING_TAG, "@since"),
135 "24:5: " + getCheckMessage(MSG_MISSING_TAG, "@since"),
136 };
137 verifyWithInlineConfigParserTwice(
138 getPath("InputWriteTagEnum.java"), expected
139 );
140 }
141
142 @Test
143 public void testSince() throws Exception {
144 final String[] expected = {
145 "17:1: " + getCheckMessage(MSG_MISSING_TAG, "@since"),
146 "38:5: " + getCheckMessage(MSG_MISSING_TAG, "@since"),
147 };
148 verifyWithInlineConfigParserTwice(
149 getPath("InputWriteTagSince.java"),
150 expected);
151 }
152
153 @Test
154 public void testBlockComment() throws Exception {
155 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
156 verifyWithInlineConfigParserTwice(
157 getPath("InputWriteTagBlockComment.java"), expected
158 );
159 }
160
161 @Test
162 public void testMethod() throws Exception {
163 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
164 verifyWithInlineConfigParserTwice(
165 getPath("InputWriteTagMethod.java"), expected);
166 }
167
168 @Test
169 public void testIgnoreMissing() throws Exception {
170 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
171 verifyWithInlineConfigParserTwice(getPath("InputWriteTagIgnore.java"), expected);
172 }
173
174 @Test
175 public void testRegularEx() throws Exception {
176 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
177 verifyWithInlineConfigParserTwice(
178 getPath("InputWriteTagRegularExpression.java"), expected);
179 }
180
181 @Test
182 public void testRegularExError() throws Exception {
183 final String[] expected = {
184 "15: " + getCheckMessage(MSG_TAG_FORMAT, "@author", "ABC"),
185 };
186 verifyWithInlineConfigParserTwice(
187 getPath("InputWriteTagExpressionError.java"), expected);
188 }
189
190 @Test
191 public void testEnumsAndAnnotations() throws Exception {
192 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
193 verifyWithInlineConfigParserTwice(
194 getPath("InputWriteTagEnumsAndAnnotations.java"), expected);
195 }
196
197 @Test
198 public void testNoJavadocs() throws Exception {
199 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
200
201 verifyWithInlineConfigParserTwice(getPath("InputWriteTagNoJavadoc.java"), expected);
202 }
203
204 @Test
205 public void testWriteTagRecordsAndCompactCtors() throws Exception {
206 final String[] expected = {
207 "19: " + getCheckMessage(MSG_TAG_FORMAT, "@incomplete", "\\S"),
208 };
209 verifyWithInlineConfigParserTwice(
210 getPath("InputWriteTagRecordsAndCompactCtors.java"), expected);
211 }
212
213 @Test
214 public void testTagTypeAuthor() throws Exception {
215 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
216 verifyWithInlineConfigParserTwice(
217 getPath("InputWriteTagTypeAuthor.java"), expected);
218 }
219
220 @Test
221 public void testTagTypeCustom() throws Exception {
222 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
223 verifyWithInlineConfigParserTwice(
224 getPath("InputWriteTagTypeCustom.java"), expected);
225 }
226
227 @Test
228 public void testTagTypeDeprecated() throws Exception {
229 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
230 verifyWithInlineConfigParserTwice(
231 getPath("InputWriteTagTypeDeprecated.java"), expected);
232 }
233
234 @Test
235 public void testTagTypeParam() throws Exception {
236 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
237 verifyWithInlineConfigParserTwice(
238 getPath("InputWriteTagTypeParam.java"), expected);
239 }
240
241 @Test
242 public void testTagTypeReturn() throws Exception {
243 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
244 verifyWithInlineConfigParserTwice(
245 getPath("InputWriteTagTypeReturn.java"), expected);
246 }
247
248 @Test
249 public void testTagTypeSee() throws Exception {
250 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
251 verifyWithInlineConfigParserTwice(
252 getPath("InputWriteTagTypeSee.java"), expected);
253 }
254
255 @Test
256 public void testTagTypeSince() throws Exception {
257 final String[] expected = {
258 "17:1: " + getCheckMessage(MSG_MISSING_TAG, "@since"),
259 "35:19: " + getCheckMessage(MSG_MISSING_TAG, "@since"),
260 };
261 verifyWithInlineConfigParserTwice(
262 getPath("InputWriteTagTypeSince.java"), expected);
263 }
264
265 @Test
266 public void testTagTypeThrows() throws Exception {
267 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
268 verifyWithInlineConfigParserTwice(
269 getPath("InputWriteTagTypeThrows.java"), expected);
270 }
271
272 @Test
273 public void testNonTightHtml() throws Exception {
274 final String[] expected = {
275 "14: " + getCheckMessage(MSG_KEY_UNCLOSED_HTML_TAG, "p"),
276 };
277 verifyWithInlineConfigParserTwice(
278 getPath("InputWriteTagNonTightHtml.java"), expected);
279 }
280
281 @Test
282 public void testCommentAboveJavadoc() throws Exception {
283 final String[] expected = {
284 "27:5: " + getCheckMessage(MSG_MISSING_TAG, "@since"),
285 "42:5: " + getCheckMessage(MSG_MISSING_TAG, "@since"),
286 };
287 verifyWithInlineConfigParserTwice(
288 getPath("InputWriteTagCheckCommentAboveJavadoc.java"), expected);
289 }
290
291 @Test
292 public void testPackageInfo() throws Exception {
293 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
294 verifyWithInlineConfigParserTwice(
295 getPath("package-info.java"), expected);
296 }
297
298 @Test
299 public void testTwoClasses() throws Exception {
300 final String[] expected = {
301 "23:1: " + getCheckMessage(MSG_MISSING_TAG, "@incomplete"),
302 };
303 verifyWithInlineConfigParserTwice(
304 getPath("InputWriteTagTwoClasses.java"), expected);
305 }
306
307 @Test
308 public void testAnnotationProcessing() throws Exception {
309 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
310 verifyWithInlineConfigParserTwice(
311 getPath("InputWriteTagAnnotationProcessing.java"), expected);
312 }
313
314 @Test
315 public void testAnnotationValue() throws Exception {
316 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
317 verifyWithInlineConfigParserTwice(
318 getPath("InputWriteTagAnnotationValue.java"), expected);
319 }
320
321 @Test
322 public void testMultipleAnnotations() throws Exception {
323 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
324 verifyWithInlineConfigParserTwice(
325 getPath("InputWriteTagMultipleAnnotationsNoJavadoc.java"),
326 expected);
327 }
328
329 @Test
330 public void testBetweenAnnotations() throws Exception {
331 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
332 verifyWithInlineConfigParserTwice(
333 getPath("InputWriteTagSingleAnnotation.java"), expected);
334 }
335
336 @Test
337 public void testIssue20875() throws Exception {
338 final String[] expected = {
339 "17:1: " + getCheckMessage(MSG_MISSING_TAG, "@since"),
340 };
341 verifyWithInlineConfigParserTwice(
342 getPath("InputWriteTagIssue20875.java"), expected);
343 }
344
345 }