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 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.junit.jupiter.api.Test;
29
30 import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
31 import com.puppycrawl.tools.checkstyle.checks.design.HideUtilityClassConstructorCheck;
32
33 public class XpathRegressionHideUtilityClassConstructorTest extends AbstractXpathTestSupport {
34
35 private final String checkName = HideUtilityClassConstructorCheck.class.getSimpleName();
36
37 @Override
38 protected String getCheckName() {
39 return checkName;
40 }
41
42 @Test
43 public void testDefaultConstructor() throws Exception {
44 final File fileToProcess =
45 new File(getPath("InputXpathHideUtilityClassConstructorDefault.java"));
46 final DefaultConfiguration moduleConfig =
47 createModuleConfig(HideUtilityClassConstructorCheck.class);
48 final String[] expectedViolation = {
49 "3:1: " + getCheckMessage(HideUtilityClassConstructorCheck.class, MSG_KEY),
50 };
51 final List<String> expectedXpathQueries = Arrays.asList(
52 "/COMPILATION_UNIT/CLASS_DEF[./IDENT[@text='"
53 + "InputXpathHideUtilityClassConstructorDefault']]",
54 "/COMPILATION_UNIT/CLASS_DEF[./IDENT[@text='"
55 + "InputXpathHideUtilityClassConstructorDefault']]/MODIFIERS",
56 "/COMPILATION_UNIT/CLASS_DEF[./IDENT[@text='"
57 + "InputXpathHideUtilityClassConstructorDefault']]/MODIFIERS/LITERAL_PUBLIC"
58 );
59
60 runVerifications(moduleConfig, fileToProcess, expectedViolation,
61 expectedXpathQueries);
62 }
63
64 @Test
65 public void testPublicConstructor() throws Exception {
66 final File fileToProcess =
67 new File(getPath("InputXpathHideUtilityClassConstructorPublic.java"));
68 final DefaultConfiguration moduleConfig =
69 createModuleConfig(HideUtilityClassConstructorCheck.class);
70 final String[] expectedViolation = {
71 "3:1: " + getCheckMessage(HideUtilityClassConstructorCheck.class, MSG_KEY),
72 };
73 final List<String> expectedXpathQueries = Arrays.asList(
74 "/COMPILATION_UNIT/CLASS_DEF[./IDENT[@text='"
75 + "InputXpathHideUtilityClassConstructorPublic']]",
76 "/COMPILATION_UNIT/CLASS_DEF[./IDENT[@text='"
77 + "InputXpathHideUtilityClassConstructorPublic']]/MODIFIERS",
78 "/COMPILATION_UNIT/CLASS_DEF[./IDENT[@text='"
79 + "InputXpathHideUtilityClassConstructorPublic']]/MODIFIERS/LITERAL_PUBLIC"
80 );
81
82 runVerifications(moduleConfig, fileToProcess, expectedViolation,
83 expectedXpathQueries);
84 }
85 }