1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.checkstyle.suppressionxpathfilter.coding;
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.coding.ArrayTrailingCommaCheck;
32
33 public class XpathRegressionArrayTrailingCommaTest extends AbstractXpathTestSupport {
34
35 private final String checkName = ArrayTrailingCommaCheck.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/coding/arraytrailingcomma";
45 }
46
47 @Test
48 public void testOne() throws Exception {
49 final File fileToProcess =
50 new File(getPath("InputXpathArrayTrailingCommaLinear.java"));
51
52 final DefaultConfiguration moduleConfig =
53 createModuleConfig(ArrayTrailingCommaCheck.class);
54
55 final String[] expectedViolation = {
56 "16:9: " + getCheckMessage(ArrayTrailingCommaCheck.class,
57 ArrayTrailingCommaCheck.MSG_KEY),
58 };
59
60 final List<String> expectedXpathQueries = Arrays.asList(
61 "/COMPILATION_UNIT/CLASS_DEF"
62 + "[./IDENT[@text='InputXpathArrayTrailingCommaLinear']]"
63 + "/OBJBLOCK/VARIABLE_DEF[./IDENT[@text='a2']]/ASSIGN/EXPR/LITERAL_NEW"
64 + "/ARRAY_INIT/EXPR[./NUM_INT[@text='3']]",
65 "/COMPILATION_UNIT/CLASS_DEF"
66 + "[./IDENT[@text='InputXpathArrayTrailingCommaLinear']]"
67 + "/OBJBLOCK/VARIABLE_DEF[./IDENT[@text='a2']]/ASSIGN/EXPR/LITERAL_NEW"
68 + "/ARRAY_INIT/EXPR/NUM_INT[@text='3']"
69 );
70
71 runVerifications(moduleConfig, fileToProcess, expectedViolation,
72 expectedXpathQueries);
73 }
74
75 @Test
76 public void testTwo() throws Exception {
77 final File fileToProcess =
78 new File(getPath("InputXpathArrayTrailingCommaMatrix.java"));
79
80 final DefaultConfiguration moduleConfig =
81 createModuleConfig(ArrayTrailingCommaCheck.class);
82
83 final String[] expectedViolation = {
84 "17:9: " + getCheckMessage(ArrayTrailingCommaCheck.class,
85 ArrayTrailingCommaCheck.MSG_KEY),
86 };
87
88 final List<String> expectedXpathQueries = Collections.singletonList(
89 "/COMPILATION_UNIT/CLASS_DEF"
90 + "[./IDENT[@text='InputXpathArrayTrailingCommaMatrix']]"
91 + "/OBJBLOCK/VARIABLE_DEF[./IDENT[@text='d2']]/ASSIGN/EXPR/LITERAL_NEW"
92 + "/ARRAY_INIT/ARRAY_INIT[./EXPR/NUM_INT[@text='5']]"
93 );
94
95 runVerifications(moduleConfig, fileToProcess, expectedViolation,
96 expectedXpathQueries);
97 }
98
99 }