1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.checkstyle.suppressionxpathfilter;
21
22 import static com.puppycrawl.tools.checkstyle.checks.TodoCommentCheck.MSG_KEY;
23
24 import java.io.File;
25 import java.util.Collections;
26 import java.util.List;
27
28 import org.junit.jupiter.api.Test;
29
30 import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
31 import com.puppycrawl.tools.checkstyle.checks.TodoCommentCheck;
32
33 public class XpathRegressionTodoCommentTest extends AbstractXpathTestSupport {
34
35 private final String checkName = TodoCommentCheck.class.getSimpleName();
36
37 @Override
38 protected String getCheckName() {
39 return checkName;
40 }
41
42 @Test
43 public void testSingleLine() throws Exception {
44 final File fileToProcess =
45 new File(getPath("InputXpathTodoCommentSingleLine.java"));
46
47 final DefaultConfiguration moduleConfig =
48 createModuleConfig(TodoCommentCheck.class);
49 moduleConfig.addProperty("format", "FIXME:");
50
51 final String[] expectedViolation = {
52 "4:7: " + getCheckMessage(TodoCommentCheck.class, MSG_KEY, "FIXME:"),
53 };
54
55 final List<String> expectedXpathQueries = Collections.singletonList(
56 "/COMPILATION_UNIT/CLASS_DEF[./IDENT[@text="
57 + "'InputXpathTodoCommentSingleLine']]/OBJBLOCK/"
58 + "SINGLE_LINE_COMMENT/COMMENT_CONTENT[@text=' warn FIXME:\\n']");
59
60 runVerifications(moduleConfig, fileToProcess, expectedViolation,
61 expectedXpathQueries);
62 }
63
64 @Test
65 public void testBlock() throws Exception {
66 final File fileToProcess =
67 new File(getPath("InputXpathTodoCommentBlock.java"));
68
69 final DefaultConfiguration moduleConfig =
70 createModuleConfig(TodoCommentCheck.class);
71 moduleConfig.addProperty("format", "FIXME:");
72
73 final String[] expectedViolation = {
74 "4:7: " + getCheckMessage(TodoCommentCheck.class, MSG_KEY, "FIXME:"),
75 };
76
77 final List<String> expectedXpathQueries = Collections.singletonList(
78 "/COMPILATION_UNIT/CLASS_DEF[./IDENT[@text="
79 + "'InputXpathTodoCommentBlock']]/"
80 + "OBJBLOCK/BLOCK_COMMENT_BEGIN/COMMENT_CONTENT"
81 + "[@text=' // warn\\n * FIXME:\\n * TODO\\n ']"
82 );
83
84 runVerifications(moduleConfig, fileToProcess, expectedViolation,
85 expectedXpathQueries);
86 }
87
88 @Test
89 public void testInsideMethod() throws Exception {
90 final File fileToProcess =
91 new File(getPath("InputXpathTodoCommentInsideMethod.java"));
92
93 final DefaultConfiguration moduleConfig =
94 createModuleConfig(TodoCommentCheck.class);
95 moduleConfig.addProperty("format", "FIXME:");
96
97 final String[] expectedViolation = {
98 "5:11: " + getCheckMessage(TodoCommentCheck.class, MSG_KEY, "FIXME:"),
99 };
100
101 final List<String> expectedXpathQueries = Collections.singletonList(
102 "/COMPILATION_UNIT/CLASS_DEF[./IDENT[@text="
103 + "'InputXpathTodoCommentInsideMethod']]/OBJBLOCK/"
104 + "METHOD_DEF[./IDENT[@text='method']]/SLIST/"
105 + "SINGLE_LINE_COMMENT/COMMENT_CONTENT[@text=' FIXME: //warn\\n']"
106 );
107
108 runVerifications(moduleConfig, fileToProcess, expectedViolation,
109 expectedXpathQueries);
110 }
111
112 }