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.MissingJavadocPackageCheck.MSG_PKG_JAVADOC_MISSING;
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 MissingJavadocPackageCheckTest extends AbstractModuleTestSupport {
32
33 @Override
34 protected String getPackageLocation() {
35 return "com/puppycrawl/tools/checkstyle/checks/javadoc/missingjavadocpackage";
36 }
37
38 @Test
39 public void testPackageJavadocPresent() throws Exception {
40 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
41 verifyWithInlineConfigParser(getPath("package-info.java"), expected);
42 }
43
44 @Test
45 public void testPackageSingleLineJavadocPresent() throws Exception {
46 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
47 verifyWithInlineConfigParser(getPath("singleline/package-info.java"), expected);
48 }
49
50 @Test
51 public void testPackageJavadocPresentWithAnnotation() throws Exception {
52 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
53 verifyWithInlineConfigParser(getPath("annotation/package-info.java"), expected);
54 }
55
56 @Test
57 public void testPackageJavadocPresentWithBlankLines() throws Exception {
58 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
59 verifyWithInlineConfigParser(getPath("blank/package-info.java"), expected);
60 }
61
62 @Test
63 public void testPackageJavadocMissing() throws Exception {
64 final String[] expected = {
65 "7:1: " + getCheckMessage(MSG_PKG_JAVADOC_MISSING),
66 };
67 verifyWithInlineConfigParser(getPath("nojavadoc/package-info.java"), expected);
68 }
69
70 @Test
71 public void testBlockCommentInsteadOfJavadoc() throws Exception {
72 final String[] expected = {
73 "10:1: " + getCheckMessage(MSG_PKG_JAVADOC_MISSING),
74 };
75 verifyWithInlineConfigParser(
76 getPath("nojavadoc/blockcomment/package-info.java"), expected);
77 }
78
79 @Test
80 public void testSinglelineCommentInsteadOfJavadoc() throws Exception {
81 final String[] expected = {
82 "8:1: " + getCheckMessage(MSG_PKG_JAVADOC_MISSING),
83 };
84 verifyWithInlineConfigParser(
85 getPath("nojavadoc/singleline/package-info.java"), expected);
86 }
87
88 @Test
89 public void testSinglelineCommentInsteadOfJavadoc2() throws Exception {
90 final String[] expected = {
91 "8:1: " + getCheckMessage(MSG_PKG_JAVADOC_MISSING),
92 };
93 verifyWithInlineConfigParser(
94 getPath("nojavadoc/single/package-info.java"), expected);
95 }
96
97 @Test
98 public void testPackageJavadocMissingWithAnnotation() throws Exception {
99 final String[] expected = {
100 "8:1: " + getCheckMessage(MSG_PKG_JAVADOC_MISSING),
101 };
102 verifyWithInlineConfigParser(
103 getPath("nojavadoc/annotation/package-info.java"), expected);
104 }
105
106 @Test
107 public void testPackageJavadocMissingWithAnnotationAndBlockComment() throws Exception {
108 final String[] expected = {
109 "12:1: " + getCheckMessage(MSG_PKG_JAVADOC_MISSING),
110 };
111 verifyWithInlineConfigParser(
112 getPath("nojavadoc/annotation/blockcomment/package-info.java"), expected);
113 }
114
115 @Test
116 public void testPackageJavadocMissingDetachedJavadoc() throws Exception {
117 final String[] expected = {
118 "11:1: " + getCheckMessage(MSG_PKG_JAVADOC_MISSING),
119 };
120 verifyWithInlineConfigParser(
121 getPath("nojavadoc/detached/package-info.java"), expected);
122 }
123
124 @Test
125 public void testPackageJavadocPresentWithHeader() throws Exception {
126 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
127 verifyWithInlineConfigParser(getPath("header/package-info.java"), expected);
128 }
129
130 @Test
131 public void testPackageJavadocMissingWithBlankLines() throws Exception {
132 final String[] expected = {
133 "8:1: " + getCheckMessage(MSG_PKG_JAVADOC_MISSING),
134 };
135 verifyWithInlineConfigParser(
136 getPath("nojavadoc/blank/package-info.java"), expected);
137 }
138
139 @Test
140 public void testNotPackageInfo() throws Exception {
141 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
142 verifyFilterWithInlineConfigParser(
143 getPath("InputMissingJavadocPackageNotPackageInfo-package-info.java"), expected);
144 }
145
146 @Test
147 public void testTokensAreCorrect() {
148 final MissingJavadocPackageCheck check = new MissingJavadocPackageCheck();
149 final int[] expected = {
150 TokenTypes.PACKAGE_DEF,
151 };
152 assertWithMessage("Acceptable required tokens are invalid")
153 .that(check.getAcceptableTokens())
154 .isEqualTo(expected);
155 assertWithMessage("Default required tokens are invalid")
156 .that(check.getDefaultTokens())
157 .isEqualTo(expected);
158 assertWithMessage("Required required tokens are invalid")
159 .that(check.getRequiredTokens())
160 .isEqualTo(expected);
161 }
162 }