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.modifier.InterfaceMemberImpliedModifierCheck;
30
31 public class XpathRegressionInterfaceMemberImpliedModifierTest extends AbstractXpathTestSupport {
32
33 @Override
34 protected String getCheckName() {
35 return InterfaceMemberImpliedModifierCheck.class.getSimpleName();
36 }
37
38 @Test
39 public void testField() throws Exception {
40 final File fileToProcess = new File(
41 getPath("InputXpathInterfaceMemberImpliedModifierField.java")
42 );
43
44 final DefaultConfiguration moduleConfig =
45 createModuleConfig(InterfaceMemberImpliedModifierCheck.class);
46
47 final String[] expectedViolation = {
48 "4:5: " + getCheckMessage(InterfaceMemberImpliedModifierCheck.class,
49 InterfaceMemberImpliedModifierCheck.MSG_KEY, "final"),
50 };
51
52 final List<String> expectedXpathQueries = Arrays.asList(
53 "/COMPILATION_UNIT/INTERFACE_DEF[./IDENT"
54 + "[@text='InputXpathInterfaceMemberImpliedModifierField']]"
55 + "/OBJBLOCK/VARIABLE_DEF[./IDENT[@text='str']]",
56
57 "/COMPILATION_UNIT/INTERFACE_DEF[./IDENT"
58 + "[@text='InputXpathInterfaceMemberImpliedModifierField']]"
59 + "/OBJBLOCK/VARIABLE_DEF[./IDENT[@text='str']]"
60 + "/MODIFIERS",
61
62 "/COMPILATION_UNIT/INTERFACE_DEF[./IDENT"
63 + "[@text='InputXpathInterfaceMemberImpliedModifierField']]"
64 + "/OBJBLOCK/VARIABLE_DEF[./IDENT[@text='str']]"
65 + "/MODIFIERS/LITERAL_PUBLIC"
66 );
67
68 runVerifications(moduleConfig, fileToProcess, expectedViolation, expectedXpathQueries);
69 }
70
71 @Test
72 public void testMethod() throws Exception {
73 final File fileToProcess = new File(
74 getPath("InputXpathInterfaceMemberImpliedModifierMethod.java")
75 );
76
77 final DefaultConfiguration moduleConfig =
78 createModuleConfig(InterfaceMemberImpliedModifierCheck.class);
79
80 final String[] expectedViolation = {
81 "4:5: " + getCheckMessage(InterfaceMemberImpliedModifierCheck.class,
82 InterfaceMemberImpliedModifierCheck.MSG_KEY, "public"),
83 };
84
85 final List<String> expectedXpathQueries = Arrays.asList(
86 "/COMPILATION_UNIT/INTERFACE_DEF[./IDENT"
87 + "[@text='InputXpathInterfaceMemberImpliedModifierMethod']]"
88 + "/OBJBLOCK/METHOD_DEF[./IDENT[@text='setData']]",
89
90 "/COMPILATION_UNIT/INTERFACE_DEF[./IDENT"
91 + "[@text='InputXpathInterfaceMemberImpliedModifierMethod']]"
92 + "/OBJBLOCK/METHOD_DEF[./IDENT[@text='setData']]"
93 + "/MODIFIERS",
94
95 "/COMPILATION_UNIT/INTERFACE_DEF[./IDENT"
96 + "[@text='InputXpathInterfaceMemberImpliedModifierMethod']]"
97 + "/OBJBLOCK/METHOD_DEF[./IDENT[@text='setData']]"
98 + "/MODIFIERS/ABSTRACT"
99 );
100
101 runVerifications(moduleConfig, fileToProcess, expectedViolation, expectedXpathQueries);
102 }
103
104 @Test
105 public void testInner() throws Exception {
106 final File fileToProcess = new File(
107 getPath("InputXpathInterfaceMemberImpliedModifierInner.java")
108 );
109
110 final DefaultConfiguration moduleConfig =
111 createModuleConfig(InterfaceMemberImpliedModifierCheck.class);
112
113 final String[] expectedViolation = {
114 "4:5: " + getCheckMessage(InterfaceMemberImpliedModifierCheck.class,
115 InterfaceMemberImpliedModifierCheck.MSG_KEY, "static"),
116 };
117
118 final List<String> expectedXpathQueries = Arrays.asList(
119 "/COMPILATION_UNIT/INTERFACE_DEF[./IDENT"
120 + "[@text='InputXpathInterfaceMemberImpliedModifierInner']]"
121 + "/OBJBLOCK/INTERFACE_DEF[./IDENT[@text='Data']]",
122
123 "/COMPILATION_UNIT/INTERFACE_DEF[./IDENT"
124 + "[@text='InputXpathInterfaceMemberImpliedModifierInner']]"
125 + "/OBJBLOCK/INTERFACE_DEF[./IDENT[@text='Data']]"
126 + "/MODIFIERS",
127
128 "/COMPILATION_UNIT/INTERFACE_DEF[./IDENT"
129 + "[@text='InputXpathInterfaceMemberImpliedModifierInner']]"
130 + "/OBJBLOCK/INTERFACE_DEF[./IDENT[@text='Data']]"
131 + "/MODIFIERS/LITERAL_PUBLIC"
132 );
133
134 runVerifications(moduleConfig, fileToProcess, expectedViolation, expectedXpathQueries);
135 }
136 }