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.JavadocContentLocationCheck.MSG_JAVADOC_CONTENT_FIRST_LINE;
24 import static com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocContentLocationCheck.MSG_JAVADOC_CONTENT_SECOND_LINE;
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 JavadocContentLocationCheckTest extends AbstractModuleTestSupport {
33
34 @Override
35 protected String getPackageLocation() {
36 return "com/puppycrawl/tools/checkstyle/checks/javadoc/javadoccontentlocation";
37 }
38
39 @Test
40 public void testGetAcceptableTokens() {
41 final JavadocContentLocationCheck checkObj = new JavadocContentLocationCheck();
42 final int[] expected = {TokenTypes.BLOCK_COMMENT_BEGIN };
43 assertWithMessage("Acceptable tokens are invalid")
44 .that(checkObj.getAcceptableTokens())
45 .isEqualTo(expected);
46 }
47
48 @Test
49 public void testGetDefaultTokens() {
50 final JavadocContentLocationCheck checkObj = new JavadocContentLocationCheck();
51 final int[] expected = {TokenTypes.BLOCK_COMMENT_BEGIN };
52 assertWithMessage("Default tokens are invalid")
53 .that(checkObj.getDefaultTokens())
54 .isEqualTo(expected);
55 }
56
57 @Test
58 public void testDefault() throws Exception {
59 final String[] expected = {
60 "17:5: " + getCheckMessage(MSG_JAVADOC_CONTENT_SECOND_LINE),
61 "21:5: " + getCheckMessage(MSG_JAVADOC_CONTENT_SECOND_LINE),
62 };
63 verifyWithInlineConfigParser(
64 getPath("InputJavadocContentLocationDefault.java"), expected);
65 }
66
67 @Test
68 public void testFirstLine() throws Exception {
69 final String[] expected = {
70 "12:5: " + getCheckMessage(MSG_JAVADOC_CONTENT_FIRST_LINE),
71 "21:5: " + getCheckMessage(MSG_JAVADOC_CONTENT_FIRST_LINE),
72 };
73 verifyWithInlineConfigParser(
74 getPath("InputJavadocContentLocationFirstLine.java"), expected);
75 }
76
77 @Test
78 public void testPackage() throws Exception {
79 final String[] expected = {
80 "8:1: " + getCheckMessage(MSG_JAVADOC_CONTENT_SECOND_LINE),
81 };
82 verifyWithInlineConfigParser(
83 getPath("package-info.java"), expected);
84 }
85
86 @Test
87 public void testInterface() throws Exception {
88 final String[] expected = {
89 "10:1: " + getCheckMessage(MSG_JAVADOC_CONTENT_FIRST_LINE),
90 };
91 verifyWithInlineConfigParser(
92 getPath("InputJavadocContentLocationInterface.java"), expected);
93 }
94
95 @Test
96 public void testOptionalSpacesAndAsterisks() throws Exception {
97 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
98 verifyWithInlineConfigParser(
99 getPath("InputJavadocContentLocationTrailingSpace.java"), expected);
100 }
101
102 @Test
103 public void testTrimOptionProperty() throws Exception {
104 final String[] expected = {
105 "12:5: " + getCheckMessage(MSG_JAVADOC_CONTENT_FIRST_LINE),
106 "21:5: " + getCheckMessage(MSG_JAVADOC_CONTENT_FIRST_LINE),
107 };
108 verifyWithInlineConfigParser(
109 getPath("InputJavadocContentLocationTrimOptionProperty.java"), expected);
110 }
111
112 @Test
113 public void testDefault2() throws Exception {
114 final String[] expected = {
115 "9:1: " + getCheckMessage(MSG_JAVADOC_CONTENT_SECOND_LINE),
116 };
117 verifyWithInlineConfigParser(
118 getPath("InputJavadocContentLocation.java"), expected);
119 }
120 }