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.List;
25
26 import org.junit.jupiter.api.Test;
27
28 import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
29 import com.puppycrawl.tools.checkstyle.checks.UncommentedMainCheck;
30
31 public class XpathRegressionUncommentedMainTest extends AbstractXpathTestSupport {
32
33 private static final Class<UncommentedMainCheck> CLAZZ =
34 UncommentedMainCheck.class;
35
36 @Override
37 protected String getCheckName() {
38 return CLAZZ.getSimpleName();
39 }
40
41 @Test
42 public void testDefault() throws Exception {
43 final File fileToProcess =
44 new File(getPath("InputXpathUncommentedMainDefault.java"));
45
46 final DefaultConfiguration moduleConfig =
47 createModuleConfig(UncommentedMainCheck.class);
48
49 final String[] expectedViolation = {
50 "4:5: " + getCheckMessage(UncommentedMainCheck.class,
51 UncommentedMainCheck.MSG_KEY),
52 };
53
54 final List<String> expectedXpathQueries = Arrays.asList(
55 "/COMPILATION_UNIT/CLASS_DEF"
56 + "[./IDENT[@text='InputXpathUncommentedMainDefault']]"
57 + "/OBJBLOCK/METHOD_DEF[./IDENT[@text='main']]",
58 "/COMPILATION_UNIT/CLASS_DEF"
59 + "[./IDENT[@text='InputXpathUncommentedMainDefault']]"
60 + "/OBJBLOCK/METHOD_DEF[./IDENT[@text='main']]/MODIFIERS",
61 "/COMPILATION_UNIT/CLASS_DEF"
62 + "[./IDENT[@text='InputXpathUncommentedMainDefault']]"
63 + "/OBJBLOCK/METHOD_DEF[./IDENT[@text='main']]/MODIFIERS/LITERAL_PUBLIC"
64 );
65
66 runVerifications(moduleConfig, fileToProcess, expectedViolation,
67 expectedXpathQueries);
68 }
69
70 @Test
71 public void testInStaticClass() throws Exception {
72 final File fileToProcess =
73 new File(getPath("InputXpathUncommentedMainInStaticClass.java"));
74
75 final DefaultConfiguration moduleConfig =
76 createModuleConfig(UncommentedMainCheck.class);
77
78 final String[] expectedViolation = {
79 "5:9: " + getCheckMessage(UncommentedMainCheck.class,
80 UncommentedMainCheck.MSG_KEY),
81 };
82
83 final List<String> expectedXpathQueries = Arrays.asList(
84 "/COMPILATION_UNIT/CLASS_DEF"
85 + "[./IDENT[@text='InputXpathUncommentedMainInStaticClass']]"
86 + "/OBJBLOCK/CLASS_DEF[./IDENT[@text='Launcher']"
87 + "]/OBJBLOCK/METHOD_DEF[./IDENT[@text='main']]",
88 "/COMPILATION_UNIT/CLASS_DEF"
89 + "[./IDENT[@text='InputXpathUncommentedMainInStaticClass']]"
90 + "/OBJBLOCK/CLASS_DEF[./IDENT[@text='Launcher']]"
91 + "/OBJBLOCK/METHOD_DEF[./IDENT[@text='main']]/MODIFIERS",
92 "/COMPILATION_UNIT/CLASS_DEF"
93 + "[./IDENT[@text='InputXpathUncommentedMainInStaticClass']]"
94 + "/OBJBLOCK/CLASS_DEF[./IDENT[@text='Launcher']]"
95 + "/OBJBLOCK/METHOD_DEF[./IDENT[@text='main']]/MODIFIERS/LITERAL_PUBLIC"
96 );
97
98 runVerifications(moduleConfig, fileToProcess, expectedViolation,
99 expectedXpathQueries);
100 }
101 }