1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.checkstyle.suppressionxpathfilter.whitespace;
21
22 import java.io.File;
23 import java.util.Collections;
24 import java.util.List;
25
26 import org.checkstyle.suppressionxpathfilter.AbstractXpathTestSupport;
27 import org.junit.jupiter.api.Test;
28
29 import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
30 import com.puppycrawl.tools.checkstyle.checks.whitespace.AbstractParenPadCheck;
31 import com.puppycrawl.tools.checkstyle.checks.whitespace.PadOption;
32 import com.puppycrawl.tools.checkstyle.checks.whitespace.ParenPadCheck;
33
34 public class XpathRegressionParenPadTest extends AbstractXpathTestSupport {
35
36 private final String checkName = ParenPadCheck.class.getSimpleName();
37
38 @Override
39 protected String getCheckName() {
40 return checkName;
41 }
42
43 @Override
44 protected String getPackageLocation() {
45 return "org/checkstyle/suppressionxpathfilter/whitespace/parenpad";
46 }
47
48 @Test
49 public void testLeftFollowed() throws Exception {
50 final File fileToProcess =
51 new File(getPath("InputXpathParenPadLeftFollowed.java"));
52
53 final DefaultConfiguration moduleConfig =
54 createModuleConfig(ParenPadCheck.class);
55
56 final String[] expectedViolation = {
57 "5:12: " + getCheckMessage(ParenPadCheck.class,
58 AbstractParenPadCheck.MSG_WS_FOLLOWED, "("),
59 };
60
61 final List<String> expectedXpathQueries = Collections.singletonList(
62 "/COMPILATION_UNIT/CLASS_DEF"
63 + "[./IDENT[@text='InputXpathParenPadLeftFollowed']]"
64 + "/OBJBLOCK/METHOD_DEF[./IDENT[@text='method']]/SLIST/LITERAL_IF/LPAREN"
65 );
66
67 runVerifications(moduleConfig, fileToProcess, expectedViolation,
68 expectedXpathQueries);
69 }
70
71 @Test
72 public void testLeftNotFollowed() throws Exception {
73 final File fileToProcess =
74 new File(getPath("InputXpathParenPadLeftNotFollowed.java"));
75
76 final DefaultConfiguration moduleConfig =
77 createModuleConfig(ParenPadCheck.class);
78 moduleConfig.addProperty("option", PadOption.SPACE.toString());
79
80 final String[] expectedViolation = {
81 "5:12: " + getCheckMessage(ParenPadCheck.class,
82 AbstractParenPadCheck.MSG_WS_NOT_FOLLOWED, "("),
83 };
84
85 final List<String> expectedXpathQueries = Collections.singletonList(
86 "/COMPILATION_UNIT/CLASS_DEF"
87 + "[./IDENT[@text='InputXpathParenPadLeftNotFollowed']]"
88 + "/OBJBLOCK/METHOD_DEF[./IDENT[@text='method']]/SLIST/LITERAL_IF/LPAREN"
89 );
90
91 runVerifications(moduleConfig, fileToProcess, expectedViolation,
92 expectedXpathQueries);
93 }
94
95 @Test
96 public void testRightPreceded() throws Exception {
97 final File fileToProcess =
98 new File(getPath("InputXpathParenPadRightPreceded.java"));
99
100 final DefaultConfiguration moduleConfig =
101 createModuleConfig(ParenPadCheck.class);
102
103 final String[] expectedViolation = {
104 "5:19: " + getCheckMessage(ParenPadCheck.class,
105 AbstractParenPadCheck.MSG_WS_PRECEDED, ")"),
106 };
107
108 final List<String> expectedXpathQueries = Collections.singletonList(
109 "/COMPILATION_UNIT/CLASS_DEF"
110 + "[./IDENT[@text='InputXpathParenPadRightPreceded']]"
111 + "/OBJBLOCK/METHOD_DEF[./IDENT[@text='method']]/SLIST/LITERAL_IF/RPAREN"
112 );
113
114 runVerifications(moduleConfig, fileToProcess, expectedViolation,
115 expectedXpathQueries);
116 }
117
118 @Test
119 public void testRightNotPreceded() throws Exception {
120 final File fileToProcess =
121 new File(getPath("InputXpathParenPadRightNotPreceded.java"));
122
123 final DefaultConfiguration moduleConfig =
124 createModuleConfig(ParenPadCheck.class);
125 moduleConfig.addProperty("option", PadOption.SPACE.toString());
126
127 final String[] expectedViolation = {
128 "5:19: " + getCheckMessage(ParenPadCheck.class,
129 AbstractParenPadCheck.MSG_WS_NOT_PRECEDED, ")"),
130 };
131
132 final List<String> expectedXpathQueries = Collections.singletonList(
133 "/COMPILATION_UNIT/CLASS_DEF"
134 + "[./IDENT[@text='InputXpathParenPadRightNotPreceded']]"
135 + "/OBJBLOCK/METHOD_DEF[./IDENT[@text='method']]/SLIST/LITERAL_IF/RPAREN"
136 );
137
138 runVerifications(moduleConfig, fileToProcess, expectedViolation,
139 expectedXpathQueries);
140 }
141
142 }