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.Arrays;
24 import java.util.Collections;
25 import java.util.List;
26
27 import org.checkstyle.suppressionxpathfilter.AbstractXpathTestSupport;
28 import org.junit.jupiter.api.Test;
29
30 import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
31 import com.puppycrawl.tools.checkstyle.checks.whitespace.SeparatorWrapCheck;
32
33 public class XpathRegressionSeparatorWrapTest extends AbstractXpathTestSupport {
34
35 private final String checkName = SeparatorWrapCheck.class.getSimpleName();
36
37 @Override
38 protected String getCheckName() {
39 return checkName;
40 }
41
42 @Override
43 protected String getPackageLocation() {
44 return "org/checkstyle/suppressionxpathfilter/whitespace/separatorwrap";
45 }
46
47 @Test
48 public void testClass() throws Exception {
49 final File fileToProcess =
50 new File(getPath("InputXpathSeparatorWrapClass.java"));
51 final DefaultConfiguration moduleConfig =
52 createModuleConfig(SeparatorWrapCheck.class);
53
54 final String[] expectedViolation = {
55 "10:17: " + getCheckMessage(SeparatorWrapCheck.class,
56 SeparatorWrapCheck.MSG_LINE_PREVIOUS, ","),
57 };
58
59 final List<String> expectedXpathQueries = Collections.singletonList(
60 "/COMPILATION_UNIT/CLASS_DEF"
61 + "[./IDENT[@text='InputXpathSeparatorWrapClass']]"
62 + "/OBJBLOCK/METHOD_DEF[./IDENT[@text='testMethod']]"
63 + "/PARAMETERS/COMMA"
64 );
65
66 runVerifications(moduleConfig, fileToProcess, expectedViolation,
67 expectedXpathQueries);
68 }
69
70 @Test
71 public void testInterface() throws Exception {
72 final File fileToProcess =
73 new File(getPath("InputXpathSeparatorWrapInterface.java"));
74
75 final DefaultConfiguration moduleConfig =
76 createModuleConfig(SeparatorWrapCheck.class);
77 moduleConfig.addProperty("tokens", "ELLIPSIS");
78 final String[] expectedViolation = {
79 "9:13: " + getCheckMessage(SeparatorWrapCheck.class,
80 SeparatorWrapCheck.MSG_LINE_PREVIOUS, "..."),
81 };
82
83 final List<String> expectedXpathQueries = Collections.singletonList(
84 "/COMPILATION_UNIT/INTERFACE_DEF"
85 + "[./IDENT[@text='InputXpathSeparatorWrapInterface']]"
86 + "/OBJBLOCK/METHOD_DEF[./IDENT[@text='testMethod2']]"
87 + "/PARAMETERS/PARAMETER_DEF"
88 + "[./IDENT[@text='parameters']]/ELLIPSIS"
89 );
90 runVerifications(moduleConfig, fileToProcess, expectedViolation,
91 expectedXpathQueries);
92 }
93
94 @Test
95 public void testMethod() throws Exception {
96 final File fileToProcess =
97 new File(getPath("InputXpathSeparatorWrapMethod.java"));
98
99 final DefaultConfiguration moduleConfig =
100 createModuleConfig(SeparatorWrapCheck.class);
101 moduleConfig.addProperty("tokens", "DOT");
102
103 final String[] expectedViolation = {
104 "9:13: " + getCheckMessage(SeparatorWrapCheck.class,
105 SeparatorWrapCheck.MSG_LINE_PREVIOUS, "."),
106 };
107 final List<String> expectedXpathQueries = Arrays.asList(
108 "/COMPILATION_UNIT/CLASS_DEF[./IDENT[@text="
109 + "'InputXpathSeparatorWrapMethod']]"
110 + "/OBJBLOCK/METHOD_DEF[./IDENT[@text='method1']]/SLIST"
111 + "/VARIABLE_DEF[./IDENT[@text='stringLength']]"
112 + "/ASSIGN/EXPR",
113 "/COMPILATION_UNIT/CLASS_DEF[./IDENT[@text="
114 + "'InputXpathSeparatorWrapMethod']]"
115 + "/OBJBLOCK/METHOD_DEF[./IDENT[@text='method1']]/SLIST"
116 + "/VARIABLE_DEF[./IDENT[@text='stringLength']]/ASSIGN"
117 + "/EXPR/DOT[./IDENT[@text='stringArray']]"
118 );
119 runVerifications(moduleConfig, fileToProcess, expectedViolation,
120 expectedXpathQueries);
121 }
122 }