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.PreferLiteralJavadocInlineTagCheck.MSG_KEY;
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 PreferLiteralJavadocInlineTagCheckTest extends AbstractModuleTestSupport {
32
33 @Override
34 public String getPackageLocation() {
35 return "com/puppycrawl/tools/checkstyle/checks/javadoc/preferliteraljavadocinlinetag";
36 }
37
38 @Test
39 public void testGetRequiredTokens() {
40 final PreferLiteralJavadocInlineTagCheck checkObj =
41 new PreferLiteralJavadocInlineTagCheck();
42 final int[] expected = {TokenTypes.BLOCK_COMMENT_BEGIN};
43 assertWithMessage("Default required tokens are invalid")
44 .that(checkObj.getRequiredTokens())
45 .isEqualTo(expected);
46 }
47
48 @Test
49 public void testPreferJavadocInlineTagsCorrect() throws Exception {
50 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
51
52 verifyWithInlineConfigParser(
53 getPath("InputPreferLiteralJavadocInlineTagCorrect.java"), expected);
54 }
55
56 @Test
57 public void testPreferJavadocInlineTagsAngleBracketEntities() throws Exception {
58 final String[] expected = {
59 "17:11: " + getCheckMessage(MSG_KEY, "&"),
60 "17:19: " + getCheckMessage(MSG_KEY, """),
61 "17:28: " + getCheckMessage(MSG_KEY, "'"),
62 "17:35: " + getCheckMessage(MSG_KEY, "<"),
63 "17:40: " + getCheckMessage(MSG_KEY, ">"),
64 "25:26: " + getCheckMessage(MSG_KEY, "<"),
65 "25:31: " + getCheckMessage(MSG_KEY, ">"),
66 "34:8: " + getCheckMessage(MSG_KEY, "<"),
67 "34:13: " + getCheckMessage(MSG_KEY, ">"),
68 "41:8: " + getCheckMessage(MSG_KEY, ">"),
69 "42:8: " + getCheckMessage(MSG_KEY, "'"),
70 "42:19: " + getCheckMessage(MSG_KEY, """),
71 "54:11: " + getCheckMessage(MSG_KEY, "<"),
72 "54:16: " + getCheckMessage(MSG_KEY, ">"),
73 "55:18: " + getCheckMessage(MSG_KEY, "&"),
74 "55:26: " + getCheckMessage(MSG_KEY, ">"),
75 "65:11: " + getCheckMessage(MSG_KEY, ">"),
76 };
77
78 verifyWithInlineConfigParser(
79 getPath("InputPreferLiteralJavadocInlineTagAngleBracketEntities.java"), expected);
80 }
81
82 @Test
83 public void testMultipleEntitiesInLine() throws Exception {
84 final String[] expected = {
85 "16:14: " + getCheckMessage(MSG_KEY, "<"),
86 "16:19: " + getCheckMessage(MSG_KEY, ">"),
87 "16:28: " + getCheckMessage(MSG_KEY, "<"),
88 "16:33: " + getCheckMessage(MSG_KEY, ">"),
89 "26:14: " + getCheckMessage(MSG_KEY, "&"),
90 "26:19: " + getCheckMessage(MSG_KEY, "&"),
91 "26:32: " + getCheckMessage(MSG_KEY, "&"),
92 "26:37: " + getCheckMessage(MSG_KEY, "&"),
93 };
94
95 verifyWithInlineConfigParser(
96 getPath("InputPreferLiteralJavadocInlineTagMultipleEntities.java"), expected);
97 }
98
99 @Test
100 public void testEdgeCases() throws Exception {
101 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
102 verifyWithInlineConfigParser(
103 getPath("InputPreferLiteralJavadocInlineTagEdgeCases.java"), expected);
104 }
105
106 @Test
107 public void testPreferJavadocInlineTagsCheckInsideInlineTagsSkipped() throws Exception {
108 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
109 verifyWithInlineConfigParser(
110 getPath("InputPreferLiteralJavadocInlineTagSkipInsideInlineTags.java"), expected);
111 }
112
113 @Test
114 public void testPreferJavadocInlineTagsCheckCompactDefault() throws Exception {
115 final String[] expected = {
116 "17:19: " + getCheckMessage(MSG_KEY, "<"),
117 "17:24: " + getCheckMessage(MSG_KEY, ">"),
118 "17:29: " + getCheckMessage(MSG_KEY, "&"),
119 "17:35: " + getCheckMessage(MSG_KEY, """),
120 "17:42: " + getCheckMessage(MSG_KEY, "'"),
121 };
122 verifyWithInlineConfigParser(
123 getNonCompilablePath(
124 "compact/InputPreferLiteralJavadocInlineTagCompactSourceFile.java"),
125 expected);
126 }
127
128 }