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 java.io.File;
23 import java.util.Collections;
24 import java.util.List;
25
26 import org.junit.jupiter.api.Test;
27
28 import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
29 import com.puppycrawl.tools.checkstyle.checks.MultilineCommentLeadingAsteriskPresenceCheck;
30
31 public class XpathRegressionMultilineCommentLeadingAsteriskPresenceTest
32 extends AbstractXpathTestSupport {
33
34 private final String checkName =
35 MultilineCommentLeadingAsteriskPresenceCheck.class.getSimpleName();
36
37 @Override
38 protected String getCheckName() {
39 return checkName;
40 }
41
42 @Test
43 public void testMultilineCommentLeadingAsteriskPresence() throws Exception {
44 final File fileProcess =
45 new File(getPath("InputXpathMultilineCommentLeadingAsteriskPresenceOne.java"));
46 final DefaultConfiguration config =
47 createModuleConfig(MultilineCommentLeadingAsteriskPresenceCheck.class);
48
49 final String[] expected = {
50 "4:5: " + getCheckMessage(
51 MultilineCommentLeadingAsteriskPresenceCheck.class,
52 MultilineCommentLeadingAsteriskPresenceCheck.MSG_MISSING_ASTERISK, "5"),
53 };
54
55 final List<String> expectedXpathQueries = Collections.singletonList(
56 "/COMPILATION_UNIT/CLASS_DEF[./IDENT"
57 + "[@text='InputXpathMultilineCommentLeadingAsteriskPresenceOne']]"
58 + "/OBJBLOCK/METHOD_DEF[./IDENT[@text='method']]/MODIFIERS"
59 + "/BLOCK_COMMENT_BEGIN[./COMMENT_CONTENT"
60 + "[@text=' // warn\\n line5\\n ']]"
61 );
62
63 runVerifications(config, fileProcess, expected, expectedXpathQueries);
64 }
65
66 @Test
67 public void testMultilineCommentLeadingAsteriskPresenceTwo() throws Exception {
68 final File fileProcess =
69 new File(getPath("InputXpathMultilineCommentLeadingAsteriskPresenceTwo.java"));
70 final DefaultConfiguration config =
71 createModuleConfig(MultilineCommentLeadingAsteriskPresenceCheck.class);
72
73 final String[] expected = {
74 "3:1: " + getCheckMessage(
75 MultilineCommentLeadingAsteriskPresenceCheck.class,
76 MultilineCommentLeadingAsteriskPresenceCheck.MSG_MISSING_ASTERISK, "4"),
77 };
78
79 final List<String> expectedXpathQueries = Collections.singletonList(
80 "/COMPILATION_UNIT/CLASS_DEF[./IDENT"
81 + "[@text='InputXpathMultilineCommentLeadingAsteriskPresenceTwo']]"
82 + "/MODIFIERS/BLOCK_COMMENT_BEGIN[./COMMENT_CONTENT"
83 + "[@text=' // warn\\n line4\\n ']]"
84 );
85
86 runVerifications(config, fileProcess, expected, expectedXpathQueries);
87 }
88
89 @Test
90 public void testMultilineCommentLeadingAsteriskPresenceThree() throws Exception {
91 final File fileProcess =
92 new File(getPath("InputXpathMultilineCommentLeadingAsteriskPresenceThree.java"));
93 final DefaultConfiguration config =
94 createModuleConfig(MultilineCommentLeadingAsteriskPresenceCheck.class);
95
96 final String[] expected = {
97 "5:9: " + getCheckMessage(
98 MultilineCommentLeadingAsteriskPresenceCheck.class,
99 MultilineCommentLeadingAsteriskPresenceCheck.MSG_MISSING_ASTERISK, "6"),
100 };
101
102 final List<String> expectedXpathQueries = Collections.singletonList(
103 "/COMPILATION_UNIT/CLASS_DEF[./IDENT"
104 + "[@text='InputXpathMultilineCommentLeadingAsteriskPresenceThree']]"
105 + "/OBJBLOCK/METHOD_DEF[./IDENT[@text='method']]/SLIST/BLOCK_COMMENT_BEGIN"
106 + "[./COMMENT_CONTENT[@text=' // warn\\n line6\\n ']]"
107 );
108
109 runVerifications(config, fileProcess, expected, expectedXpathQueries);
110 }
111
112 }