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