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.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.coding.MissingCtorCheck;
31
32 public class XpathRegressionMissingCtorTest extends AbstractXpathTestSupport {
33
34 private final String checkName = MissingCtorCheck.class.getSimpleName();
35
36 @Override
37 protected String getCheckName() {
38 return checkName;
39 }
40
41 @Override
42 protected String getPackageLocation() {
43 return "org/checkstyle/suppressionxpathfilter/coding/missingctor";
44 }
45
46 @Test
47 public void testMissingCtor() throws Exception {
48 final File fileToProcess = new File(getPath(
49 "InputXpathMissingCtor.java"));
50
51 final DefaultConfiguration moduleConfig =
52 createModuleConfig(MissingCtorCheck.class);
53
54 final String[] expectedViolation = {
55 "3:1: " + getCheckMessage(MissingCtorCheck.class,
56 MissingCtorCheck.MSG_KEY),
57 };
58
59 final List<String> expectedXpathQueries = Arrays.asList(
60 "/COMPILATION_UNIT/CLASS_DEF"
61 + "[./IDENT[@text='InputXpathMissingCtor']]",
62 "/COMPILATION_UNIT/CLASS_DEF"
63 + "[./IDENT[@text='InputXpathMissingCtor']]/MODIFIERS",
64 "/COMPILATION_UNIT/CLASS_DEF[./IDENT["
65 + "@text='InputXpathMissingCtor']]/MODIFIERS/LITERAL_PUBLIC"
66 );
67
68 runVerifications(moduleConfig, fileToProcess, expectedViolation,
69 expectedXpathQueries);
70 }
71
72 @Test
73 public void testInnerClass() throws Exception {
74 final File fileToProcess = new File(getPath(
75 "InputXpathMissingCtorInner.java"));
76
77 final DefaultConfiguration moduleConfig =
78 createModuleConfig(MissingCtorCheck.class);
79
80 final String[] expectedViolation = {
81 "9:5: " + getCheckMessage(MissingCtorCheck.class,
82 MissingCtorCheck.MSG_KEY),
83 };
84
85 final List<String> expectedXpathQueries = Arrays.asList(
86 "/COMPILATION_UNIT/CLASS_DEF[./IDENT["
87 + "@text='InputXpathMissingCtorInner']]"
88 + "/OBJBLOCK/CLASS_DEF[./IDENT[@text='InnerClass']]",
89 "/COMPILATION_UNIT/CLASS_DEF[./IDENT["
90 + "@text='InputXpathMissingCtorInner']]"
91 + "/OBJBLOCK/CLASS_DEF[./IDENT[@text='InnerClass']]/MODIFIERS",
92 "/COMPILATION_UNIT/CLASS_DEF[./IDENT["
93 + "@text='InputXpathMissingCtorInner']]"
94 + "/OBJBLOCK/CLASS_DEF[./IDENT[@text='InnerClass']]/LITERAL_CLASS"
95 );
96
97 runVerifications(moduleConfig, fileToProcess, expectedViolation,
98 expectedXpathQueries);
99 }
100
101 }