1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.checkstyle.suppressionxpathfilter.design;
21
22 import static com.puppycrawl.tools.checkstyle.checks.design.HideUtilityClassConstructorCheck.MSG_KEY;
23
24 import java.io.File;
25 import java.util.Arrays;
26 import java.util.List;
27
28 import org.checkstyle.suppressionxpathfilter.AbstractXpathTestSupport;
29 import org.junit.jupiter.api.Test;
30
31 import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
32 import com.puppycrawl.tools.checkstyle.checks.design.HideUtilityClassConstructorCheck;
33
34 public class XpathRegressionHideUtilityClassConstructorTest extends AbstractXpathTestSupport {
35
36 private final String checkName = HideUtilityClassConstructorCheck.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/design/hideutilityclassconstructor";
46 }
47
48 @Test
49 public void testDefaultConstructor() throws Exception {
50 final File fileToProcess =
51 new File(getPath("InputXpathHideUtilityClassConstructorDefault.java"));
52 final DefaultConfiguration moduleConfig =
53 createModuleConfig(HideUtilityClassConstructorCheck.class);
54 final String[] expectedViolation = {
55 "3:1: " + getCheckMessage(HideUtilityClassConstructorCheck.class, MSG_KEY),
56 };
57 final List<String> expectedXpathQueries = Arrays.asList(
58 "/COMPILATION_UNIT/CLASS_DEF[./IDENT[@text='"
59 + "InputXpathHideUtilityClassConstructorDefault']]",
60 "/COMPILATION_UNIT/CLASS_DEF[./IDENT[@text='"
61 + "InputXpathHideUtilityClassConstructorDefault']]/MODIFIERS",
62 "/COMPILATION_UNIT/CLASS_DEF[./IDENT[@text='"
63 + "InputXpathHideUtilityClassConstructorDefault']]/MODIFIERS/LITERAL_PUBLIC"
64 );
65
66 runVerifications(moduleConfig, fileToProcess, expectedViolation,
67 expectedXpathQueries);
68 }
69
70 @Test
71 public void testPublicConstructor() throws Exception {
72 final File fileToProcess =
73 new File(getPath("InputXpathHideUtilityClassConstructorPublic.java"));
74 final DefaultConfiguration moduleConfig =
75 createModuleConfig(HideUtilityClassConstructorCheck.class);
76 final String[] expectedViolation = {
77 "3:1: " + getCheckMessage(HideUtilityClassConstructorCheck.class, MSG_KEY),
78 };
79 final List<String> expectedXpathQueries = Arrays.asList(
80 "/COMPILATION_UNIT/CLASS_DEF[./IDENT[@text='"
81 + "InputXpathHideUtilityClassConstructorPublic']]",
82 "/COMPILATION_UNIT/CLASS_DEF[./IDENT[@text='"
83 + "InputXpathHideUtilityClassConstructorPublic']]/MODIFIERS",
84 "/COMPILATION_UNIT/CLASS_DEF[./IDENT[@text='"
85 + "InputXpathHideUtilityClassConstructorPublic']]/MODIFIERS/LITERAL_PUBLIC"
86 );
87
88 runVerifications(moduleConfig, fileToProcess, expectedViolation,
89 expectedXpathQueries);
90 }
91 }