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