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.AbstractJavadocCheck.MSG_KEY_UNCLOSED_HTML_TAG;
24 import static com.puppycrawl.tools.checkstyle.checks.javadoc.IllegalBlockTagCheck.MSG_ILLEGAL_PATTERN;
25
26 import org.junit.jupiter.api.Test;
27
28 import com.puppycrawl.tools.checkstyle.AbstractModuleTestSupport;
29 import com.puppycrawl.tools.checkstyle.api.TokenTypes;
30 import com.puppycrawl.tools.checkstyle.utils.CommonUtil;
31
32 public class IllegalBlockTagCheckTest extends AbstractModuleTestSupport {
33
34 @Override
35 public String getPackageLocation() {
36 return "com/puppycrawl/tools/checkstyle/checks/javadoc/illegalblocktag";
37 }
38
39 @Test
40 public void testGetAcceptableTokens() {
41 final IllegalBlockTagCheck checkObj = new IllegalBlockTagCheck();
42 final int[] expected = {
43 TokenTypes.INTERFACE_DEF,
44 TokenTypes.CLASS_DEF,
45 TokenTypes.ENUM_DEF,
46 TokenTypes.ANNOTATION_DEF,
47 TokenTypes.METHOD_DEF,
48 TokenTypes.CTOR_DEF,
49 TokenTypes.ENUM_CONSTANT_DEF,
50 TokenTypes.ANNOTATION_FIELD_DEF,
51 TokenTypes.RECORD_DEF,
52 TokenTypes.COMPACT_CTOR_DEF,
53 };
54 assertWithMessage("Default acceptable tokens are invalid")
55 .that(checkObj.getAcceptableTokens())
56 .isEqualTo(expected);
57 }
58
59 @Test
60 public void testGetRequiredTokens() {
61 final IllegalBlockTagCheck checkObj = new IllegalBlockTagCheck();
62 assertWithMessage("Required tokens should be empty")
63 .that(checkObj.getRequiredTokens())
64 .isEqualTo(CommonUtil.EMPTY_INT_ARRAY);
65 }
66
67 @Test
68 public void testGetDefaultTokens() {
69 final IllegalBlockTagCheck checkObj = new IllegalBlockTagCheck();
70 assertWithMessage("Default tokens should match acceptable tokens")
71 .that(checkObj.getDefaultTokens())
72 .isEqualTo(checkObj.getAcceptableTokens());
73 }
74
75 @Test
76 public void testJavadocTokens() {
77 final IllegalBlockTagCheck checkObj = new IllegalBlockTagCheck();
78 assertWithMessage("Required javadoc tokens should match acceptable javadoc tokens")
79 .that(checkObj.getRequiredJavadocTokens())
80 .isEqualTo(checkObj.getAcceptableJavadocTokens());
81 assertWithMessage("Default javadoc tokens should not be empty")
82 .that(checkObj.getDefaultJavadocTokens())
83 .isNotEmpty();
84 }
85
86 @Test
87 public void testDefaultSettings() throws Exception {
88 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
89 verifyWithInlineConfigParser(getPath("InputIllegalBlockTagDefault.java"), expected);
90 }
91
92 @Test
93 public void testTagPresence() throws Exception {
94 final String[] expected = {
95 "17:4: " + getCheckMessage(MSG_ILLEGAL_PATTERN, "todo"),
96 "30:8: " + getCheckMessage(MSG_ILLEGAL_PATTERN, "todo"),
97 };
98 verifyWithInlineConfigParser(getPath("InputIllegalBlockTagPresence.java"), expected);
99 }
100
101 @Test
102 public void testIllegalPattern() throws Exception {
103 final String[] expected = {
104 "21:8: " + getCheckMessage(MSG_ILLEGAL_PATTERN, "since"),
105 "29:8: " + getCheckMessage(MSG_ILLEGAL_PATTERN, "since"),
106 };
107 verifyWithInlineConfigParser(getPath("InputIllegalBlockTagPattern.java"), expected);
108 }
109
110 @Test
111 public void testNoJavadoc() throws Exception {
112 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
113 verifyWithInlineConfigParser(getPath("InputIllegalBlockTagNoJavadoc.java"), expected);
114 }
115
116 @Test
117 public void testAnnotationJavadoc() throws Exception {
118 final String[] expected = {
119 "16:4: " + getCheckMessage(MSG_ILLEGAL_PATTERN, "todo"),
120 };
121 verifyWithInlineConfigParser(getPath("InputIllegalBlockTagAnnotation.java"), expected);
122 }
123
124 @Test
125 public void testEmptyTagContent() throws Exception {
126
127 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
128 verifyWithInlineConfigParser(getPath("InputIllegalBlockTagEmptyTag.java"), expected);
129 }
130
131 @Test
132 public void testEnumConstant() throws Exception {
133 final String[] expected = {
134 "17:8: " + getCheckMessage(MSG_ILLEGAL_PATTERN, "todo"),
135 };
136 verifyWithInlineConfigParser(getPath("InputIllegalBlockTagEnumConstant.java"), expected);
137 }
138
139 @Test
140 public void testInlineTagContent() throws Exception {
141 final String[] expected = {
142 "18:8: " + getCheckMessage(MSG_ILLEGAL_PATTERN, "todo"),
143 };
144 verifyWithInlineConfigParser(
145 getPath("InputIllegalBlockTagInlineContent.java"), expected);
146 }
147
148 @Test
149 public void testFullTagContentPattern() throws Exception {
150 final String[] expected = {
151 "25:8: " + getCheckMessage(MSG_ILLEGAL_PATTERN, "todo"),
152 };
153 verifyWithInlineConfigParser(
154 getPath("InputIllegalBlockTagFullContent.java"), expected);
155 }
156
157 @Test
158 public void testNonTightHtml() throws Exception {
159 final String[] expected = {
160 "16: " + getCheckMessage(MSG_KEY_UNCLOSED_HTML_TAG, "p"),
161 };
162 verifyWithInlineConfigParser(
163 getPath("InputIllegalBlockTagNonTightHtml.java"), expected);
164 }
165
166 @Test
167 public void testTypeComment() throws Exception {
168 final String[] expected = {
169 "17:8: " + getCheckMessage(MSG_ILLEGAL_PATTERN, "todo"),
170 "25:8: " + getCheckMessage(MSG_ILLEGAL_PATTERN, "todo"),
171 };
172 verifyWithInlineConfigParser(
173 getPath("InputIllegalBlockTagTypeComment.java"), expected);
174 }
175
176 }