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.javadoc.MissingJavadocMethodCheck;
30
31 public class XpathRegressionMissingJavadocMethodTest extends AbstractXpathTestSupport {
32
33 @Override
34 protected String getCheckName() {
35 return MissingJavadocMethodCheck.class.getSimpleName();
36 }
37
38 @Test
39 public void testMissingJavadocMethodCtor() throws Exception {
40 final File fileToProcess = new File(
41 getPath("InputXpathMissingJavadocMethodCtor.java")
42 );
43
44 final DefaultConfiguration moduleConfig =
45 createModuleConfig(MissingJavadocMethodCheck.class);
46 moduleConfig.addProperty("tokens", "CTOR_DEF");
47
48 final String[] expectedViolation = {
49 "4:5: " + getCheckMessage(MissingJavadocMethodCheck.class,
50 MissingJavadocMethodCheck.MSG_JAVADOC_MISSING),
51 };
52
53 final List<String> expectedXpathQueries = Arrays.asList(
54 "/COMPILATION_UNIT/CLASS_DEF[./IDENT"
55 + "[@text='InputXpathMissingJavadocMethodCtor']]"
56 + "/OBJBLOCK/CTOR_DEF[."
57 + "/IDENT[@text='InputXpathMissingJavadocMethodCtor']]",
58
59 "/COMPILATION_UNIT/CLASS_DEF"
60 + "[./IDENT[@text='InputXpathMissingJavadocMethodCtor']]"
61 + "/OBJBLOCK/CTOR_DEF[."
62 + "/IDENT[@text='InputXpathMissingJavadocMethodCtor']]"
63 + "/MODIFIERS",
64
65 "/COMPILATION_UNIT/CLASS_DEF"
66 + "[./IDENT[@text='InputXpathMissingJavadocMethodCtor']]"
67 + "/OBJBLOCK/CTOR_DEF[."
68 + "/IDENT[@text='InputXpathMissingJavadocMethodCtor']]"
69 + "/MODIFIERS/LITERAL_PUBLIC"
70 );
71
72 runVerifications(moduleConfig, fileToProcess, expectedViolation, expectedXpathQueries);
73 }
74
75 @Test
76 public void testMissingJavadocMethod() throws Exception {
77 final File fileToProcess = new File(
78 getPath("InputXpathMissingJavadocMethod.java")
79 );
80
81 final DefaultConfiguration moduleConfig =
82 createModuleConfig(MissingJavadocMethodCheck.class);
83 moduleConfig.addProperty("tokens", "METHOD_DEF");
84
85 final String[] expectedViolation = {
86 "4:5: " + getCheckMessage(MissingJavadocMethodCheck.class,
87 MissingJavadocMethodCheck.MSG_JAVADOC_MISSING),
88 };
89
90 final List<String> expectedXpathQueries = Arrays.asList(
91 "/COMPILATION_UNIT/CLASS_DEF"
92 + "[./IDENT[@text='InputXpathMissingJavadocMethod']]"
93 + "/OBJBLOCK/METHOD_DEF[./IDENT[@text='foo']]",
94
95 "/COMPILATION_UNIT/CLASS_DEF"
96 + "[./IDENT[@text='InputXpathMissingJavadocMethod']]"
97 + "/OBJBLOCK/METHOD_DEF[./IDENT[@text='foo']]"
98 + "/MODIFIERS",
99
100 "/COMPILATION_UNIT/CLASS_DEF"
101 + "[./IDENT[@text='InputXpathMissingJavadocMethod']]"
102 + "/OBJBLOCK/METHOD_DEF[./IDENT[@text='foo']]"
103 + "/MODIFIERS/LITERAL_PUBLIC"
104 );
105
106 runVerifications(moduleConfig, fileToProcess, expectedViolation, expectedXpathQueries);
107 }
108 }